我正在使用HTML / PHP开展学校项目。现在我遇到了问题,我们的PHP文件/bid.php没有检索我们的HTML表单的输入数据。 提交表单时,我们收到以下错误:
解析错误:语法错误,第4行的D:\ School \ IN \ USBWebserver v8.5 \ USBWebserver v8.5 \ 8.5 \ root \ bid.php中的意外T_VARIABLE
提前感谢您的帮助!
编辑:
我已经编辑了我的代码,就像我从各种来源找到的那样。它目前没有任何错误回应。让我想知道问题是什么,因为插入的值不会出现在我的数据库中。 掩饰 .php
<form method="post" action="/bid.php">
<input type="text" name="bod" placeholder="bod">
<input type="text" name="naam" placeholder="naam">
<input type="text" name="item" placeholder="Item Nummer">
<input type="submit">
</form>
<?php
$bod = $_POST['bod'];
$naam = $_POST['naam'];
$item = $_POST['item'];
?>
bid.php
<?php
$bid = isset($_POST['bod']) ? $_POST['bod'] : false;
$name = isset($_POST['naam']) ? $_POST['naam'] : false;
$item = isset($_POST['item']) ? $_POST['item'] : false;
$connect = mysql_connect('localhost', 'root', 'usbw');
mysql_select_db ('veiling');
$sql = "INSERT into personeel (name, bod, item)
VALUES ('$name', '$bid', '$item')";
$res = mysql_query($sql);
mysql_close ($connect); ?>
veiling html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<form method="get" action="/bid.php">
<input type="text" name="bod" placeholder="bod">
<input type="text" name="naam" placeholder="naam">
<input type="text" name="item" placeholder="Item Nummer">
<input type="submit">
</form>
</body>
</html>
出价php
<?php
$conn = mysql_connect(localhost, root, usbw);
mysql_select_db ('veiling')
$bid = $_GET['bod']
$name = $_GET['naam']
$item = $_GET['item']
$maxbid = mysql_query(SELECT MAX(bod) FROM veiling WHERE item=1)
if $bid =< $maxbid then
exit
else
INSERT INTO veiling (bod, naam, item)
VALUES ($bid, $name, $item)
// SQL
echo('Gefeliciteerd '$name', het bod op item ' $item ' van €' $bid 'is succesvol toegevoegd')
?>
我们的数据库
CREATE TABLE IF NOT EXISTS `veiling` (
`id` int(3) NOT NULL AUTO_INCREMENT,
`name` varchar(25) NOT NULL,
`bod` varchar(20) NOT NULL,
`item` int(3) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
答案 0 :(得分:2)
你错过了;在你的行尾。
<?php
$conn = mysql_connect(localhost, root, usbw);
mysql_select_db ('veiling');
$bid = $_GET['bod'];
$name = $_GET['naam'];
$item = $_GET['item'];
$maxbid = mysql_query("SELECT MAX(bod) FROM veiling WHERE item=1");
$maxbid = mysql_fetch_array($maxbid);
if( $bid =< $maxbid[0] )
{
die();
}
else
{
mysql_query("INSERT INTO veiling (bod, naam, item) VALUES ($bid, $name, $item)");
// You should escape the parameters with mysql_real_escape_string.
// SQL
echo 'Gefeliciteerd '$name', het bod op item ' $item ' van €' $bid 'is succesvol toegevoegd';
}
?>
此代码应该有效。
您还应注意,自PHP 5.5起,不推荐使用mysql_ *函数。我建议你改用PDO。
答案 1 :(得分:0)
你的许多陈述错过了所需的分号。我编辑了你的代码:
<?php
$conn = mysql_connect(localhost, root, usbw);
mysql_select_db ('veiling');
$bid = $_GET['bod'];
$name = $_GET['naam'];
$item = $_GET['item'];
$maxbid = mysql_query("SELECT MAX(bod) FROM veiling WHERE item=1");
$maxbid = mysql_fetch_array($maxbid);
if( $bid <= $maxbid[0] ) //notice the <= not =<
{
die();
}
else
{ //note the single quotes around $name and $item
mysql_query("INSERT INTO veiling (bod, naam, item) VALUES ($bid, '$name', '$item')");
//note the dot(.) concatenating your string with the variables
echo 'Gefeliciteerd '. $name. ', het bod op item '. $item. ' van €'. $bid. 'is succesvol toegevoegd';
}
?>
此代码应该可以使用
答案 2 :(得分:-1)
你从
开始错过了分号mysql_select_db ('veiling')
答案 3 :(得分:-2)
代码中的错误太少我改变了一些尝试这个 变化,
<?php
$conn = mysql_connect(localhost, root, usbw);
mysql_select_db ('veiling')
$bid = $_GET['bod']
$name = $_GET['naam']
$item = $_GET['item']
$maxbid = mysql_query(SELECT MAX(bod) FROM veiling WHERE item=1)
if $bid =< $maxbid then
exit
else
INSERT INTO veiling (bod, naam, item)
VALUES ($bid, $name, $item)
// SQL
echo('Gefeliciteerd '$name', het bod op item ' $item ' van €' $bid 'is succesvol toegevoegd')
?>
像这样,
<?php
$conn = mysql_connect(localhost, root, usbw);
mysql_select_db ('veiling');
$bid = $_GET['bod'];
$name = $_GET['naam'];
$item = $_GET['item'] ;
$maxbid = mysql_query(SELECT MAX(bod) FROM veiling WHERE item=1);
if ($bid =< $maxbid)
exit
else
INSERT INTO veiling (bod, naam, item)
VALUES ($bid, $name, $item)
// SQL
echo('Gefeliciteerd '$name', het bod op item ' $item ' van €' $bid 'is succesvol toegevoegd');
?>