网站不支持FireFox,但适用于Safari和Chrome

时间:2017-06-12 04:27:14

标签: php html

我创建了一个简单的网站,允许用户销售商品,然后查看待售商品列表。它在Safari和Chrome中完美运行,但它不适用于FireFox。我只是在测试期间遇到过这种情况。我将发布输入表单和处理php的代码,然后是我在Firefox中获得的错误。

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>

我收到的错误:

注意:未定义的索引:第32行的/Applications/XAMPP/xamppfiles/htdocs/ICTDBS504/sell_your_item.php中的auction_type

注意:未定义的索引:第33行的/Applications/XAMPP/xamppfiles/htdocs/ICTDBS504/sell_your_item.php中的类别

注意:未定义索引:第34行/Applications/XAMPP/xamppfiles/htdocs/ICTDBS504/sell_your_item.php中的标题

注意:未定义的索引:第35行的/Applications/XAMPP/xamppfiles/htdocs/ICTDBS504/sell_your_item.php中的描述

注意:未定义的索引:第36行的/Applications/XAMPP/xamppfiles/htdocs/ICTDBS504/sell_your_item.php中的价格

注意:未定义的索引:第37行的/Applications/XAMPP/xamppfiles/htdocs/ICTDBS504/sell_your_item.php中的持续时间

注意:未定义的索引:第38行的/Applications/XAMPP/xamppfiles/htdocs/ICTDBS504/sell_your_item.php中的数量

注意:未定义的索引:位于第39行的/Applications/XAMPP/xamppfiles/htdocs/ICTDBS504/sell_your_item.php中的位置

注意:未定义的索引:第40行的/Applications/XAMPP/xamppfiles/htdocs/ICTDBS504/sell_your_item.php中的paymentType

注意:未定义的索引:第41行的/Applications/XAMPP/xamppfiles/htdocs/ICTDBS504/sell_your_item.php中的邮资

注意:未定义索引:第46行/Applications/XAMPP/xamppfiles/htdocs/ICTDBS504/sell_your_item.php中的图片

请帮忙!

1 个答案:

答案 0 :(得分:0)

您可以直接将数据发布到sell_your_item.php,而不是将其发布到同一页面并执行所有检查并以其可行的方式保存数据。目前您只是重定向到页面但数据未传递给页面。

相关问题