PHP中出现"意外的T_OBJECT_OPERATOR"错误

jer*_*ins 22 php mysql object parse-error

我收到以下错误:

Parse error: syntax error, unexpected T_OBJECT_OPERATOR in.. on line 52.
Run Code Online (Sandbox Code Playgroud)

第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');
    }   
}
Run Code Online (Sandbox Code Playgroud)

Mic*_*ter 27

你之前忘记了美元符号$mysqli.