执行文件时,我在下面的代码中一直收到此错误。我看了一眼,似乎无法弄清楚我做错了什么:
Parse error: syntax error, unexpected T_VARIABLE in /home/w0650266/public_html/blog/viewentry.php on line 32.
第32行是以$sql = ....
if (isset($_POST['submit'])) {
//$_POST['name'] = addslashes($_POST['name']);
//$_POST['comment'] = addslashes($_POST['comment']);
$sql= "INSERT INTO comments (blog_id,dateposted,name,comment) VALUES (".$validentry.",NOW(),'".$_POST['name']."','"$_POST['comment']."');";
mysqli_query($db,$sql);
header("Location: http://".$_SERVER['HTTP_HOST'].$_SERVER[SCRIPT_NAME']."?id=".$validentry);
答案 0 :(得分:1)
添加一个点“。”在SQL查询中$_POST['comment']
之前。
答案 1 :(得分:0)
更改您的代码并使用以下内容:
语法编辑错误:
...
$sql= "INSERT INTO comments (blog_id,dateposted,name,comment) VALUES (".$validentry.",NOW(),'".$_POST['name']."','".$_POST['comment']."')";
...
答案 2 :(得分:-1)
以下代码使用:
if (isset($_POST['submit'])) {
//$_POST['name'] = addslashes($_POST['name']);
//$_POST['comment'] = addslashes($_POST['comment']);
$sql= "INSERT INTO comments (blog_id,dateposted,name,comment) VALUES ('".$validentry."',NOW(),'".$_POST['name']."','".$_POST['comment']."')";
mysqli_query($db,$sql);
header("Location: http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']."?id=".$validentry);
答案 3 :(得分:-1)
$sql= "INSERT INTO comments (blog_id,dateposted,name,comment) VALUES (".$validentry.",NOW(),'".$_POST['name']."','"$_POST['comment']."');";
如上所示纠正以上行,
$sql= "INSERT INTO comments (blog_id,dateposted,name,comment) VALUES ('".$validentry."',NOW(),'".$_POST['name']."','".$_POST['comment']."')";
改变是:
. before $_POST['comment']
".$validentry."
应为'".$validentry."'