• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PHP Fatal error: Call to a member function bind_param()
#1
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();
  Reply
#2
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.
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)