2017-06-12 11 views
0

私は単純なウェブサイトを作って、ユーザーがアイテムを販売し、次に販売するアイテムのリストを表示できるようにした。これはSafariとChromeで完全に動作しますが、FireFoxでは動作しません。私はテスト中にこれを見つけただけです。入力フォームと処理PHPのコードを投稿し、Firefoxでエラーを表示します。FireFoxでウェブサイトが動作していないが、SafariとChromeで動作する

FORM:

<?php 
// Define variables and set to empty values 
$titleErr = $descriptionErr = $priceErr = $quantityErr = $durationErr = $locationErr = ""; 
$title = $description = $price = $quantity = $duration = $location = ""; 
$valid = FALSE; 

if ($_SERVER["REQUEST_METHOD"] == "POST") { 
$valid = TRUE; 

if (empty($_POST["title"])) { 
    $titleErr = "Title is required"; 
    $valid = FALSE; 
} 
else { 
    $title = test_input($_POST["title"]); 
} 

if (empty($_POST["description"])) { 
    $descriptionErr = "A description is required"; 
    $valid = FALSE; 
} 
else { 
    $description = test_input($_POST["description"]); 
    if (!preg_match("/^[a-zA-Z ]*$/", $description)) { 
     $descriptionErr = "Only letters and white space allowed"; 
    } 
} 

if (empty($_POST["price"])) { 
    $priceErr = "A price is required"; 
    $valid = FALSE; 
} 
else { 
    $price = test_input($_POST["price"]); 
} 

if (empty($_POST["quantity"])) { 
    $quantityErr = "A quantity is required"; 
    $valid = FALSE; 
} 
else { 
    $quantity = test_input($_POST["quantity"]); 
} 


if (empty($_POST["duration"])) { 
    $durationErr = "Duration is required"; 
    $valid = FALSE; 
} 
else { 
    $duration = test_input($_POST["duration"]); 
} 


if (empty($_POST["location"])) { 
    $locationErr = "A location is required"; 
    $valid = FALSE; 
} 
else { 
    $location = test_input($_POST["location"]); 
} 


// If valid then redirect 
if($valid){ 
    header('Location: sell_your_item.php'); 
    exit(); 
} 
} 

// Function to remove spaces, strip slashes and allow special characters to be used in form 
function test_input($data) { 
$data = trim($data); 
$data = stripslashes($data); 
$data = htmlspecialchars($data); 
return $data; 
} 

?> 
<!doctype html> 
<html> 
<head> 
<meta charset="UTF-8"> 
<title>Sell Your Item</title> 
<link href="style.css" type="text/css" rel="stylesheet"> 
</head> 

<body> 


<div> 
<h2>Sell your item</h2><br> 
<section> 
<nav id="primary_nav_wrap" data-role="navbar"> 
    <ul> 
     <li><a href="form.php">Sell an item</a></li> 
     <li><a href="list_items.php">Items for sale</a></li> 
    </ul> 
</nav> 
</section><br><br> 
<p><span class="error">* required.</span></p> 
<form method="post" onsubmit='<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>' enctype="multipart/form-data"> 
Title: &nbsp; 
<input type="text" name="title" value="<?php echo $title;?>"> 
<span class="error">* <?php echo $titleErr;?></span> 
    <br><br> 
Description: &nbsp; 
<textarea class="textarea" name="description" rows="2" cols="50" value="<?php echo $description;?>"> 
</textarea> 
<span class="error">* <?php echo $descriptionErr;?></span> 
    <br><br> 
Choose A Picture: &nbsp; 
<input type="file" name="picture" value="<?php echo $picture;?>"> 
    <br><br> 
Category: &nbsp; 
<select name="category"> 
    <option 
    value="Collectables" <?php if(isset($_POST['category']) && $_POST['category'] == 'Collectables') echo "selected"; ?>  
    name="Collectables">Collectables</option> 
    <option 
    value="Electronics" <?php if(isset($_POST['category']) && $_POST['category'] == 'Electronics') echo "selected"; ?> 
    name="Electronics">Electronics</option> 
    <option 
    value="Vehicles" <?php if(isset($_POST['category']) && $_POST['category'] == 'Vehicles') echo "selected"; ?> 
    name="Vehicles">Vehicles</option> 
    <option 
    value="Children" <?php if(isset($_POST['category']) && $_POST['category'] == 'Children') echo "selected"; ?> 
    name="Children">Children</option> 
    <option 
    value="Clothing" <?php if(isset($_POST['category']) && $_POST['category'] == 'Clothing') echo "selected"; ?> 
    name="Clothing">Clothing</option> 
    <option 
    value="Fitness" <?php if(isset($_POST['category']) && $_POST['category'] == 'Fitness') echo "selected"; ?> 
    name="Fitness">Fitness</option> 
    <option 
    value="Homegarden" <?php if(isset($_POST['category']) && $_POST['category'] == 'Homegarden') echo "selected"; ?> 
    name="Homegarden">Home &amp; Garden</option> 
</select> 
    <br><br> 
Starting Price: &nbsp; 
<input type="number" name="price" min="0.01" step="0.01" value="<?php echo $price;?>"> 
<span class="error">* <?php echo $priceErr;?></span> 
    <br><br> 
Quantity: &nbsp; 
<input type="number" name="quantity" min="1" max="99" value="<?php echo $quantity;?>"> 
<span class="error">* <?php echo $quantityErr;?></span> 
    <br><br> 
Duration (days): &nbsp; 
<input type="number" name="duration" min="1" max="10" value="<?php echo $duration;?>"> 
<span class="error">* <?php echo $durationErr;?></span> 
    <br><br> 
Location: &nbsp; 
<input type="text" name="location" value="<?php echo $location;?>"> 
<span class="error">* <?php echo $locationErr;?></span> 
    <br><br> 
Auction Type: &nbsp; 
<select name="auction_type"> 
    <option value="Fixed_price" <?php if(isset($_POST['auction_type']) && $_POST['auction_type'] == 'Fixedprice') echo "selected"; ?> 
    name="fixedprice">Fixed Price Sale</option> 
    <option value="Auction" <?php if(isset($_POST['auction_type']) && $_POST['auction_type'] == 'Auction') echo "selected"; ?> 
    name="auction">Auction</option> 
</select> 
    <br><br> 
Payment Method: &nbsp; 
<select name="paymentType"> 
    <option value="PayPal" <?php if(isset($_POST['paymentType']) && $_POST['paymentType'] == 'PayPal') echo "selected"; ?> 
    name="PayPal">PayPal</option> 
    <option value="Creditcard" <?php if(isset($_POST['paymentType']) && $_POST['paymentType'] == 'Creditcard') echo "selected"; ?> 
    name="Creditcard">Credit Card</option> 
    <option value="Bank" <?php if(isset($_POST['paymentType']) && $_POST['paymentType'] == 'Bank') echo "selected"; ?> 
    name="bank">Bank Deposit</option> 
</select> 
    <br><br> 
Postage Details: &nbsp; 
<select name="postage"> 
    <option value="Pickup" <?php if(isset($_POST['postage']) && $_POST['postage'] == 'Pickup') echo "selected"; ?> 
    name="pickup">Pick Up only</option> 
    <option value="Post" <?php if(isset($_POST['postage']) && $_POST['postage'] == 'Post') echo "selected"; ?> 
    name="post">Postage available at buyer's expense</option> 
</select> 
    <br><br> 
<input type="submit" name="submit" value="Submit"> 
</form> 
</div> 
</body> 
</html> 

SELL_YOUR_ITEM.PHP:

<!doctype html> 
<html> 
<head> 
<meta charset="UTF-8"> 
<title>Sell Your Item</title> 
</head> 

<body> 
<?php 

// Maximum file size for the html upload form 
$max_file_size = 50 * 1024 * 1024; // size in bytes 

// The directory that will recieve the uploaded file 
$dir = 'uploads/'; 

// Determine connection variables 
$servername = "localhost"; 
$username = "root"; 
$password = ""; 
$dbname = "ictdbs504"; 

// Create Connection 
$conn = new mysqli($servername, $username, $password, $dbname); 

// Check Connection 
if ($conn->connect_error) { 
die("Connection failed: " . $conn->connect_error); 
} 

// Escape user inputs for security 
$sellingFormat = mysqli_real_escape_string($conn, $_POST['auction_type']); 
$category = mysqli_real_escape_string($conn, $_REQUEST['category']); 
$title = mysqli_real_escape_string($conn, $_REQUEST['title']); 
$description = mysqli_real_escape_string($conn, $_REQUEST['description']); 
$startPrice = mysqli_real_escape_string($conn, $_REQUEST['price']); 
$duration = mysqli_real_escape_string($conn, $_REQUEST['duration']); 
$quantity = mysqli_real_escape_string($conn, $_REQUEST['quantity']); 
$location = mysqli_real_escape_string($conn, $_REQUEST['location']); 
$paymentType = mysqli_real_escape_string($conn, $_REQUEST['paymentType']); 
$postageDetails = mysqli_real_escape_string($conn, $_REQUEST['postage']); 


//variables for images 
$allowedExts = array("gif", "jpeg", "jpg", "png"); 
$temp = explode(".", $_FILES["picture"]["name"]); 
$extension = end($temp); 


$success = false; 



// Check if form submitted 
if(isset($_POST['submit'])) { 
    if (strlen($title)>0 && strlen($description)>0) { 
      $newFilePath = $dir . "/" . $title . "." . $extension; 
      move_uploaded_file($_FILES['picture']['tmp_name'], $newFilePath); 


      // Query database and insert data into item table 
      $itemQry = 'INSERT INTO items (title, picture, startPrice, category, description, quantity, location, sellingFormat, duration, paymentType, postageDetails) 
         VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; 
      $statement = $conn->prepare($itemQry); 
      $statement->bind_param('sssssssssss', $title, $newFilePath, $startPrice, $category, $description, $quantity, $location, $sellingFormat, $duration, $paymentType, $postageDetails); 
      $statement->execute(); 

      $success=true; 

    }}   
      // If successful, redirect to this page 
     if($success == true){ 
      header('Location: list_items.php'); 
      die(); } 



?> 
</body> 
</html> 

私が受け取るERROR:

お知らせ:未定義のインデックス:auction_type /アプリケーション/ XAMPP/xamppfiles/htdocsに/ ICTDBS504 /sell_your_item.php on line 32

注意:未定義のインデックス:カテゴリは/ Applic ations/XAMPP/xamppfiles/htdocsに/ ICTDBS504/sell_your_item.phpライン上の33

お知らせ:未定義のインデックス:ライン上の/Applications/XAMPP/xamppfiles/htdocs/ICTDBS504/sell_your_item.phpでタイトル34

お知らせ:未定義のインデックス:ライン上の/Applications/XAMPP/xamppfiles/htdocs/ICTDBS504/sell_your_item.phpの記述35

お知らせ:未定義のインデックス:ライン36上の/Applications/XAMPP/xamppfiles/htdocs/ICTDBS504/sell_your_item.php価格

注意:未定義のインデックス:/ Applications/XAMPP/xamppfiles/htdocs/ICTDBS504/sell_your_itemの期間ライン上の.php 37

注意:未定義のインデックス:/アプリケーション/ XAMPP/xamppfiles場所:ライン上/Applications/XAMPP/xamppfiles/htdocs/ICTDBS504/sell_your_item.phpの数量38

注意:未定義のインデックスライン上の/htdocs/ICTDBS504/sell_your_item.php 39

お知らせ:未定義のインデックス:ライン上の/Applications/XAMPP/xamppfiles/htdocs/ICTDBS504/sell_your_item.phpでpaymentType 40

お知らせ:未定義のインデックス:切手で/Applications/XAMPP/xamppfiles/htdocs/ICTDBS504/sell_your_item.php on line 41

お知らせ:未定義のインデックス:行46

に/Applications/XAMPP/xamppfiles/htdocs/ICTDBS504/sell_your_item.phpで絵助けてください!

+3

[通知:未定義の変数]、[通知:未定義のインデックス]、[通知:未定義のオフセット]](https://stackoverflow.com/questions/4261133/php-notice-undefined- variable-notice-undefined-index-and-notice-undef) – Qirel

+0

これはどのブラウザでも同じ結果になります。フォームを送信すると、そのデータはポスト配列に格納されます。別のページにリダイレクトすると、そのページはなくなります。また、テスト入力機能はほとんど役に立ちませんので、そのように使うべきではありません – Qirel

答えて

0

データをsell_your_item.phpに直接投稿するのではなく、同じページに投稿してすべてのチェックを実行し、データを保存することができます。現在はページにリダイレクトされていますが、データは渡されませんページに

+0

ありがとう、私はこれを試してみましょう。 – Joel

関連する問題