-1

我有以下代码,我暂时不认为它对于拍卖的目的是完整的,但它应该在这个阶段工作,尽管如此,据我所知。但我没有。只是想知道是否有人可以指出我的错误。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>
4

3 回答 3

2

你错过了一个花括号:

if ($bid > $current_bid) {
    $current_bid = $bid;
    $bidsubmitted = "";

} else {
    $bidsubmitted = "Your bid must exceed the current bid";
}

另外,(而且非常重要)您的代码不安全。使用PDOMySQLi将用户数据插入数据库。

$con = mysql_connect('localhost', 'root', 'password');
$db = mysql_select_db("users");

$auction = mysql_query("

SELECT * FROM auction WHERE host = '$hostuser' //This is bad.

");
于 2012-12-04T18:41:48.063 回答
0

你只是没有关闭括号

  } // instead of '{'
else{

$bidsubmitted = "Your bid must exceed the current bid";

}
于 2012-12-04T18:47:45.073 回答
0

你之前错过了},否则应该是这样的

if ($bid > $current_bid) {

$current_bid = $bid;
$bidsubmitted = "";

}
else{

$bidsubmitted = "Your bid must exceed the current bid";

}
于 2014-06-06T07:17:19.703 回答