bind_param()错误,我确保INSERT语句正确

时间:2018-06-24 16:51:07

标签: php mysql

我有此代码php,并且我确保**** INSERT ** sql **是正确的 并得到错误:

  

投入   /home/admin6asheh/public_html/newFolder/tokens/saveToken.php在线   33       [24-Jun-2018 16:37:31 UTC] PHP致命错误:未捕获的错误:在布尔值中调用成员函数bind_param()   /home/admin6asheh/public_html/newFolder/tokens/saveToken.php:33       堆栈跟踪:       #0 {main}         在线上/home/admin6asheh/public_html/newFolder/tokens/saveToken.php中抛出   33

我的代码是

<?php
define("DB_Host","localhost");
define("DB_User","mahmoud_1996");
define("DB_Password","0787676704hhh");
define("DB_Name", "newsTokens");

// Create connection
$conn = new mysqli(DB_Host,DB_User,DB_Password,DB_Name);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}


if (isset($_POST['token']) && isset($_POST['android_id'])) {

    $sql = "SELECT * FROM tokens WHERE android_ID=?";
    $stm = $conn->prepare($sql);
    $stm->bind_param('s', $_POST['android_id']);
    $stm->execute();

    if ($stm->num_rows > 0) {
        $sql = "UPDATE tokens SET token=?  WHERE android_ID=?";
        $stm = $conn->prepare($sql);
        $stm->bind_param('ss', $_POST['token'], $_POST['android_id']);

        $stmt->execute();
        echo "token update ";

    } else {
        $sql = "INSERT INTO tokens(android_ID,token) VALUES (?,?)";
        $stmt = $conn->prepare($sql);
        // get me error in this line 
        $stmt->bind_param('ss',$_POST['android_id'],$_POST['token'] );

        $stmt->execute();

        echo "insert new token";

    }


}

$conn->close();
?>

0 个答案:

没有答案