【问题标题】:Website not working on FireFox but works on Safari and Chrome网站无法在 FireFox 上运行,但可以在 Safari 和 Chrome 上运行
【发布时间】:2017-11-13 10:56:34
【问题描述】:

我制作了一个简单的网站,允许用户出售商品,然后查看待售商品的列表。它在 Safari 和 Chrome 上完美运行,但在 FireFox 上却无法运行。我只是在测试过程中遇到这个。我将发布输入表单和处理 php 的代码,然后发布我在 Firefox 中遇到的错误。

表格:

<?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 中的拍卖类型

注意:未定义索引:第 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 中的图片

请帮忙!

【问题讨论】:

标签: php html


【解决方案1】:

您可以将数据直接发布到 sell_your_item.php 而不是将其发布到同一页面并执行所有检查并保存数​​据以使其正常工作。目前您只是重定向到一个页面但数据不会传递到页面。

【讨论】:

  • 谢谢,我试试看。
猜你喜欢
  • 2018-02-04
  • 2016-08-05
  • 1970-01-01
  • 2016-10-23
  • 1970-01-01
  • 2014-05-21
  • 2022-01-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多