“Unexpected T_OBJECT_OPERATOR” error in PHP

帅比萌擦擦* 提交于 2019-12-05 09:28:13

问题


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');
    }   
}

回答1:


You forgot the dollar sign before $mysqli.



来源:https://stackoverflow.com/questions/5313705/unexpected-t-object-operator-error-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!