オークションサイトを作って、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が問題だと思います.私は通常それを使用しません..しかし、何が問題なのか非常に困惑しています. そして、私はまだ自分の入力を消毒していませんが、私はそれらを認識しています。ありがとうございました。