首页 > 解决方案 > SQL prepared statements

问题描述

I am getting this error continuously:

Call to a member function bind_param() on boolean*

It generally appears when we try operation on a table that does not exist and prepare statement returns false, but I have a structured table. My prepared statements are:

$query = "INSERT INTO `profiles`(name,email,handle,DOB,profilePic,gender,r_lat,r_lon,c_lat,"
               . "c_lon,connections,recentActivities,savedItems,achievements,school,"
               . "interestsB,interestsI,interestsE,work,coverPic,bio,fb_url,insta_url,link_url,wordpress_url,"
               . "other_url,address,range,phone)VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

PS: I am open to all suggestions.

       $stmt=$mysqli->prepare($query);
       $stmt->bind_param("ssssssddddsssssssssssssssssii",$name,$email,$handle,$DOB,$profilePic,$gender,$r_lat,$r_lon,$c_lat,$c_lon,
               $connections,$recentActivities,$savedItems,$achievements,$school,$interestsB,
               $interestsI,$interestsE,$work,$coverPic,$bio,$fb_url,$insta_url,$link_url,$wordpress_url,
               $other_url,$address,$range,$phone);
       $res = $stmt->execute();
       return $res;  

I am posting screenshots:

enter image description here

printing the error returns:

1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'range,phone)VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)' at line 1

标签: mysqlsqlsyntax-errorprepared-statementmysql-error-1064

解决方案


range is a reserved word in MySQL. You could escape it by surrounding it with forward quotes:

`range`

推荐阅读