Search code examples
phpmysqliprepared-statementbindparam

How can I use the bind_param() with multiple params


So I have a table with the colums title,description,created, fk_u. Then I have this statement:

$stmt = $conn->prepare( "insert into blogs1(title,description,created,fk_u) values(?,?,?,?)");

Afterwards I try to bind the parameters with bind_param().

$stmt->bind_param("ssii", $title,$desc,NOW(),$id);

The Problem I get is that it dosen't recognise the NOW() function. What could be the error. Am I using the bind_param function wrong?


Solution

  • NOW() is MySQL, so move this to your SQL and remove the bind...

    $stmt = $conn->prepare( "insert into blogs1(title,description,created,fk_u) 
                      values(?,?,NOW(),?)");
    
    $stmt->bind_param("ssi", $title,$desc,$id);