“意外的 T_OBJECT_OPERATOR” PHP 中的错误
我收到以下错误:
Parse error: syntax error, unexpected T_OBJECT_OPERATOR in.. on line 52.
第 52 行是 if ($result = mysqli->query...
。如果我注释掉该行,则 $mysqli-> 上会出现相同的错误;query("INSERT INTO...
。
为什么会出现错误?
$unique_code = "";
$inserted = false;
while(!$inserted) {
$unique_code = generateCode();
echo $unique_code;
// Check if it exists
if ($result = mysqli->query("SELECT unique_code FROM coming_soon_emails WHERE unique_code = '$unique_code'")) {
// Check no record exists
if ($result->num_rows == 0) {
// Create new record
$mysqli->query("INSERT INTO coming_soon_emails (email,unique_code) VALUES ('" . $mysqli->real_escape_string($_POST['email']) . "','$unique_code')");
// Set inserted to true to ext loop
$inserted = true;
// Close the result object
$result->close();
}
} else {
// Quit if we can't check the database
die('Something went wrong with select');
}
}
I am getting the following error:
Parse error: syntax error, unexpected T_OBJECT_OPERATOR in.. on line 52.
Line 52 is if ($result = mysqli->query...
. If I comment out the line, the same error occurs on $mysqli->query("INSERT INTO...
.
Why does this give the error?
$unique_code = "";
$inserted = false;
while(!$inserted) {
$unique_code = generateCode();
echo $unique_code;
// Check if it exists
if ($result = mysqli->query("SELECT unique_code FROM coming_soon_emails WHERE unique_code = '$unique_code'")) {
// Check no record exists
if ($result->num_rows == 0) {
// Create new record
$mysqli->query("INSERT INTO coming_soon_emails (email,unique_code) VALUES ('" . $mysqli->real_escape_string($_POST['email']) . "','$unique_code')");
// Set inserted to true to ext loop
$inserted = true;
// Close the result object
$result->close();
}
} else {
// Quit if we can't check the database
die('Something went wrong with select');
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您忘记了
$mysqli
之前的美元符号。You forgot the dollar sign before
$mysqli
.