当我尝试在本文末尾运行 MySQL 查询/准备语句代码时,遇到了几个解析错误。具体来说,我收到一个解析错误读数:
Parse error: syntax error, unexpected '{' in .... on line 22
第 22 行对应于第一个“if”语句的结尾。当我在第一个“if”语句(意外的';')末尾有分号时,我也遇到了同样的错误。当我删除 { 时,我会收到另一个警告:
Parse error: syntax error, unexpected T_REQUIRE_ONCE in ....on line 24
第 24 行对应于 require_once 语句。如果我将 require 语句放在代码的开头,那么我会得到另一个解析错误:
Parse error: syntax error, unexpected T_VARIABLE in ....on line 26
第 26 行对应于查询的开头。所以基本上无休止的解析错误。有点疯了。任何帮助将不胜感激。谢谢!
<?php
if (!empty($_POST['var1'])&&!empty($_POST['var2'])
&&!empty($_POST['var3'])&&isset($_POST['var4'],
$_POST['var5'], $_POST['var6']) {
require_once 'connect.inc.php';
$query = "INSERT INTO tablename (var1, var2, var3, var4, var5, var6)
VALUES (?,?,?,?,?,?)";
$stmt = mysqli_prepare($link, $query);
mysqli_stmt_bind_param($stmt, "ssssss", $var1, $var2, $var3, $var4, $var5, $var6);
$var1 = $_POST['var1'];
$var2 = $_POST['var2'];
$var3 = $_POST['var3'];
$var4 = $_POST['var4'];
$var5 = $_POST['var5'];
$var6 = $_POST['var6'];
mysqli_stmt_execute($stmt);
if (mysqli_stmt_affected_rows($stmt)==1);
mysqli_stmt_close($stmt);
$result = mysqli_query($link, $query);
if ($result) {
echo 'Thank you for your submission.';
}
else {
echo 'We were unable to process your information.'.mysqli_error($link).'
Please ensure all required fields were filled out.';
}
mysqli_close($link);
}
}
?>