0

我正在尝试制作一个拍卖网站并制作它,以便我可以在 mysql 表中更新它,但它不会更新 mysql 表中的任何内容。我得到一个 php 错误日志,我得到的所有错误都来自

t-2012 17:02:46] PHP Notice:  Undefined variable: auctionnum in /devel/cgreenheld/projects/Asgn2/auction.php on line 21

[04-Oct-2012 17:02:46] PHP Notice:  Undefined variable: reserve_met in /devel/cgreenheld/projects/Asgn2/auction.php on line 116

[04-Oct-2012 17:02:46] PHP Notice:  Undefined variable: reserve in /devel/cgreenheld/projects/Asgn2/auction.php on line 123

[04-Oct-2012 17:02:46] PHP Notice:  Undefined variable: highest_bid in /devel/cgreenheld/projects/Asgn2/auction.php on line 123

[04-Oct-2012 17:02:46] PHP Notice:  Undefined variable: highest_bid in /devel/cgreenheld/projects/Asgn2/auction.php on line 123
[04-Oct-2012 17:02:46] PHP Notice:  Undefined variable: auctionnum in /devel/cgreenheld/projects/Asgn2/auction.php on line 124

[04-Oct-2012 17:02:46] PHP Notice:  Undefined variable: title in /devel/cgreenheld/projects/Asgn2/auction.php on line 130

[04-Oct-2012 17:02:46] PHP Notice:  Undefined variable: bio in /devel/cgreenheld/projects/Asgn2/auction.php on line 131

[04-Oct-2012 17:02:46] PHP Notice:  Undefined variable: reserve_met in /devel/cgreenheld/projects/Asgn2/auction.php on line 133

[04-Oct-2012 17:02:46] PHP Notice:  Undefined variable: reserve in /devel/cgreenheld/projects/Asgn2/auction.php on line 134

我有相当多的代码,所以我会尝试将其缩小到我认为相关的位。这都是非常基本的atm,但我只是想让它能够将东西插入到mysql表中。所以这是他们进入拍卖的表格(这很好用)

<h2>Create a new Auction!</h2>
    <?php
        echo "<form method='post' action='createauction.php' enctype=multipart/form-data>";
    echo '<fieldset class="register">';
    echo"<h2>Auction Properties</h2>";
        echo "<ul>";
                echo '<li><label for="Title">Auction Title:</label> <input type="text" name="Title" id="Title"></li>';
                echo '<li><label for="Bio">Auction Description </label> <input type="text" name="Bio" id="Bio"></li>';
                echo '<li><label for="Reserve">Reserve</label><input type="text" name="Reserve" id="Reserve"></li>';
                echo '<li id="contentbox">Category:</li>';
                echo '<li><select name="Category"></li>';
                echo '<li><option value="clothing">Clothing</option></li>';
                echo '<li><option value="electronics">Electronics</option></li>';
                echo '<li><option value="living">Living</option></li>';
                echo '<li><input type="submit" value="Create"></li>';
                echo "</ul>";
    echo "</fieldset>";
    echo "</form>";
    ?>

这是将其插入表中(这也可以正常工作)

<?php
    $clean_title = $_POST['Title'];
    $clean_bio = $_POST['Bio'];
    $clean_category = $_POST['Category'];
    $username = $_SESSION['user'];
    $reserve = $_POST['Reserve'];
    $insert = 'Insert INTO Auctions(closingtime, Title, Bio, Category, Username, reserver) VALUES (NOW() + INTERVAL 7 DAY,  "'.$clean_title.'", "'.$clean_bio.'", "'.$clean_category.'", "'.$_SESSION['user'].'", "'.$reserve.'")'; 
    $result = $conn->query($insert);
    $auction_query = "select Auctionno from Auctions ORDER BY Auctionno";
    $result2 = $conn->query($auction_query);
        while ($row = $result2->fetch_assoc()) {
        $auctionnum = $row['Auctionno'];
        }
?>

<p>Your auction has been started click <a href="auction.php?id=<?php echo $auctionnum;?>">here</a> to view it.
            </p>

这将我们带到页面以查看我们的拍卖然后我们到达我们的拍卖页面,在哪里

if(isset($_GET['id'])){
  $auctionnum = $_GET['id'];
 }else{
  header("Location: browse.php");
  exit();
 }

$query = 'SELECT * FROM Auctions WHERE Auctionno = "'.$auctionnum.'";';
$result = $conn->query($query);
    while ($row = $result->fetch_assoc()) {
    $auctionnum = $row['Auctionno'];
    $title = $row['Title'];
    $bio = $row['Bio'];
    $category = $row['Category'];
    $reserve = $row['reserver'];
    $reserve_met = $row['reserve_MET'];
    $highest_bid = $row['highest_bid'];
    }
?>
<!DOCTYPE html>

<html>
    <head>
            <!--[if IE]>
    <link rel="stylesheet" href="IEstyle.css"/>
    <script>
    document.createElement('nav');
    document.createElement('section');
    document.createElement('footer'):
    document.createElement('header');
    </script>
    <![endif]-->
        <title>Bargin Bin: A place where Kiwis can buy and sell!</title>
        <meta http-equiv="content-type" content="text/html; charset=utf-8">
        <link rel="stylesheet" type="text/css" href="auction.css">
    </head>
    <body>
    <header>
        <img src="logo.gif" alt="Bargin Bin Logo">
        <ul>
        <li><a href="login.php"><b>Login</b></a></li>
        <li><a href="register.php"><b>Register</b></a></li>
        </ul>
        <?php
            if($_SESSION['authorisation'] == 'knownuser') {
                if(isset($_SESSION['user'])) {
        echo '<ul class="log">';
        echo '<li><h4>You are logged in as '.$_SESSION['user'].'</h4></li>';
        echo '<li><a href="logout.php">Logout</a></li>';
        echo "</ul>";
            }
        }
        else {
        echo "<h4>You are not logged in</h4>";
        }
        ?>
    </header>
    <nav>
    <ul>
    <li><a href="index.php">Home</a></li>
    <li><a href="browse.php"><b>Browse</b></a></li>
    <?php
    if(isset($_SESSION['authorisation'])) {
    if($_SESSION['authorisation'] == 'knownuser') {
    echo '<li><a href="account.php">MyAccount</a></li>';
    }
    }
    if(isset($_SESSION['admin'])) {
    echo '<li><a href="admin.php">Admin</a></li>';
    }
    if(isset($_SESSION['authorisation'])) {
    if($_SESSION['authorisation'] = 'knownuser') {
    echo '<li><b>MyAuction</b></li>';
    }
    }
    ?>
    </ul>
    </nav>
    <section>   
    <div id="bidbar">
    <?php
echo "<form action=\"bid.php\" method=\"post\">";
echo "<div id=\"bidbar\">";
if($reserve_met == 0){
  echo "<span>Starting bid:$</span>";
}else{
  echo "<span>Min next bid: $</span>";
}
?>

<input id="bidinput" type="text" name="bid" value="<?php echo $reserve > $highest_bid ? $reserve : $highest_bid + 1;?>" size="4">
<input type="hidden" name="auction_number" value="<?php echo $auctionnum;?>">
<input type="submit" id="bidbutton" value="click here to bid">
</div><!-- //bidbar -->
</form>

<?php
    echo "<h1 id=\"auctiontitle\">Auction Title: $title </h1>";
    echo "<p id=\auctionbio\">Auction Description: $bio</p>";
    echo "<div id=\"infobar\">";
    if($reserve_met == 0){
        echo "<span>Start Price: \$$reserve</span>";
        echo "</br>";
         echo "<span id=\"reserve\">No reserve</span>";
        }else{
        echo "<span>Highest Bid:\$$highest_bid</span>";
        echo "<span id=\"reserve\">Reserve Met</span>";
    }

?>
    </section>
    <hr>
    <footer>Courtney Greenheld Web Design 2012 Ltd.</footer>
    </body>
    </html>

然后这是我处理投标的页面。

if(isset($_POST['bid']) && isset($_POST['auctionnum'])) {
  $clean_bid = $_POST['bid'];
echo $clean_bid;
  $auctionnum = $_POST['auctionnum'];
echo $auctionnum;
  $bidder = $_SESSION['user'];
echo $bidder;
}else{
  header("Location: auction.php");
  exit();
}
$query_highest_bid = 'SELECT highest_bid FROM Auctions WHERE Auctionno = "'.$auctionnum.'";';
$result = $conn->query($insert);
$highest_array = mysql_fetch_array($result);
$highest_bid = $highest_array[0];
$query1 = 'UPDATE Auctions SET highest_bid = "'.$clean_bid.'" WHERE Auctionno = "'.$auctionnum.'";';
$result1 = $conn->query($query1);
$query2 = 'UPDATE Auctions SET highest_bidder = "'.$bidder.'" WHERE Auctionno = "'.$auctionnum.'";';
$result2 = $conn->query($query2);
$query3 = 'UPDATE Auctions SET highest_bidder = "'.$bidder.'" WHERE Auctionno = "'.$auctionnum.'";';
$result3 = $conn->query($query3);
$query4 = 'INSERT INTO BiddingUsers(Auctionno, Username, Bid) VALUES("'.$auctionnum.'" , "'.$bidder.'", "'.$clean_bid.'");';
$result4 = $conn->query($query4);
header("Location: auction.php?id=$auctionnum");

?>

我不太确定到底哪里出了问题,我认为 mysql_fetch_array 是个问题,我通常不使用它。但我对出了什么问题感到非常困惑。而且我还没有对我的输入进行分类,但我知道它们。谢谢你。

4

3 回答 3

1

Where's the connection to your database ? ($conn) I cannot see it being initialized.

Also, make sure you enable "display_errors", by adding the following code to the top of your file. this way you can debug your code properly, after that, comment or simply remove it.

ini_set('display_errors', 1);
error_reporting(E_ALL);

As a side-note to your coding style I would recommend using EOF instead of multiple echo

EX: you have:

echo "<h1 id=\"auctiontitle\">Auction Title: $title </h1>";
    echo "<p id=\auctionbio\">Auction Description: $bio</p>";
    echo "<div id=\"infobar\">";

I would recommend:

$pagina = <<< EOF
<h1 id="auctiontitle">Auction Title: $title </h1>
<p id=\auctionbio">Auction Description: $bio</p>
<div id="infobar">
more html...
EOF;
echo $pagina ;

It's easier to write and read and more error proof because you don't have to escape everything.

于 2012-10-04T04:46:30.847 回答
0

这是因为那些变量在使用之前没有定义。error_reporting(0)在 aution.php 文件的顶部 使用或为变量分配空值,例如,

$auctionnum=$title=$bio=$category=$reserve=$reserve_met=$highest_bid="";

原因:

例如,

 $temp="test";
 echo $temp;

在上面的代码$temp变量中赋值。所以它不会给你任何通知。但请看以下代码:

echo $tt;

在此代码$tt中,变量在使用之前没有定义/分配任何值。所以它会像你提到的那样发出通知。当执行以下查询时,让我们转到您的代码,在 auction.php 中,

$query = 'SELECT * FROM Auctions WHERE Auctionno = "'.$auctionnum.'";';

您将获得变量的值,例如$auctionnum, $title, $bio, $category, $reserve, $reserve_met, $highest_bid。如果查询没有记录,那么它是未分配的,你会看到 php 通知。

于 2012-10-04T05:36:33.273 回答
0

这是因为您使用了在使用它们之前未定义的变量。请在出现错误的行上使用,而不是:

 $clean_title = $_POST['Title'];
 $clean_bio = $_POST['Bio'];
 ....

请用

$clean_title = (isset($_POST['Title'])?$_POST['Title']:"");
$clean_bio = (isset($_POST['Bio'])?$_POST['Bio']:"");
....

它也可以用于其他变量,例如:代替

$title

利用

(isset($title)?$title:"")   
于 2014-11-24T13:35:59.190 回答