WP-Monkey - Official Forum
PHP Fatal error: Call to a member function bind_param() - Printable Version

+- WP-Monkey - Official Forum (https://forum.wp-monkey.com)
+-- Forum: For Developers (https://forum.wp-monkey.com/forumdisplay.php?fid=9)
+--- Forum: PHP (https://forum.wp-monkey.com/forumdisplay.php?fid=13)
+--- Thread: PHP Fatal error: Call to a member function bind_param() (/showthread.php?tid=34)



PHP Fatal error: Call to a member function bind_param() - kevin21 - 05-04-2020

I've been stuck on this error , please help me this is my code PHP Fatal error: Call to a member function bind_param()

Code:
$statement= $db->prepare("insert into uploaddetails(idnum,title,desc,author,tags,title) values(?,?,?,?,?,?)");


     $id='NULL';
    $title=$_POST['title'];
    $description=$_POST['description'];
     $author=$_POST['author'];
     $tags=$_POST['tags'];
     $file= basename($_FILES["fileToUpload"]["name"]);


    $statement->bind_param( 'isssss', $id,$title, $description,$author,$tags,$file);
    $statement->execute();

    $db->close();
    $statement->close();



RE: PHP Fatal error: Call to a member function bind_param() - Jackpro - 05-04-2020

Since nobody else has spotted the issue, I'll post it for you. The reason you're prepare() is failing is because you're trying to use a MySQL Reserved word. The word desc is a reserved word in MYSQL, which means you need to wrap it in backticks like this:
Code:
$statement= $db->prepare("insert into uploaddetails(idnum,title,`desc`,author,tags,file) values(?,?,?,?,?,?)");
It also helps to use proper practice when inserting into a database/using prepared statements.
Code:
$statement= $db->prepare("insert into uploaddetails(idnum,title,`desc`,author,tags,title) values(?,?,?,?,?,?)");

if($statement !== FALSE) {
    // do the binds...etc
}
This shall surely helps you.