我有以下代码,我认为暂时没有为拍卖目的完成但它应该在这个阶段起作用,尽管如此,据我所见。但我没有。只是想知道是否有人可以指出我的错误。 broswer说php脚本中的else是意外的。删除它会使浏览器不希望最后关闭html标记。非常感谢任何建议。干杯
<?php
$hostuser = $_GET['user'];
$auc = $_GET['auc'];
//Connect to database
$con = mysql_connect('localhost', 'root', 'password');
$db = mysql_select_db("users");
$auction = mysql_query("
SELECT * FROM auction WHERE host = '$hostuser'
");
$row = mysql_fetch_array ($auction);
$current_bid = $row['current_bid'];
$current_bid_user = $row['current_bid_user'];
$time_started = $row['time_started'];
if ($current_bid == 0) {
$current_bid = "No bids have yet been submitted. Be the first to make a bid.";
}
include ('auction_1.php');
if ($bid > $current_bid) {
$current_bid = $bid;
$bidsubmitted = "";
{
else
$bidsubmitted = "Your bid must exceed the current bid";
}
?>
<html>
<form action = 'auction_1.php' method ='POST'>
<br>
Current bid: <?php echo $current_bid; ?>
<br>
<br>
Time Left:
<table>
<br>
<br>
<tr>
<td>
Your bid:
</td>
<td>
<input type = 'text' name = 'userbid'>
</td>
</tr>
</table>
<p>
<input type='submit' name='bid' value='Bid'>
<?php echo $bidsubmitted; ?>
</html>
答案 0 :(得分:2)
你错过了大括号:
if ($bid > $current_bid) {
$current_bid = $bid;
$bidsubmitted = "";
} else {
$bidsubmitted = "Your bid must exceed the current bid";
}
另外,(并且非常重要)您的代码不安全。使用PDO
或MySQLi
将用户数据插入数据库。
$con = mysql_connect('localhost', 'root', 'password');
$db = mysql_select_db("users");
$auction = mysql_query("
SELECT * FROM auction WHERE host = '$hostuser' //This is bad.
");
答案 1 :(得分:0)
你刚才没有关闭括号
} // instead of '{'
else{
$bidsubmitted = "Your bid must exceed the current bid";
}
答案 2 :(得分:0)
你错过了}
之前它应该是这样的
if ($bid > $current_bid) {
$current_bid = $bid;
$bidsubmitted = "";
}
else{
$bidsubmitted = "Your bid must exceed the current bid";
}