PHP 中的“意外的 T_OBJECT_OPERATOR”错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5313705/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 20:58:01 来源:igfitidea点击:
“Unexpected T_OBJECT_OPERATOR” error in PHP
提问by jeremycollins
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...
.
第 52 行是if ($result = mysqli->query...
。如果我注释掉该行,则会在$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');
}
}
回答by Michiel Pater
You forgot the dollar sign before $mysqli
.
你之前忘记了美元符号$mysqli
。