views:

88

answers:

2

I'm not seeing the error and was hoping someone could figure it out:

 public static function createMessage($title, $message, $startDate, $endDate, $author, $status){
      //$dbConn is now a mysqli instance with a connection to the database foobar
      $dbConn = Database::getConnection("foobar");

      $stmt = $dbConn->prepare("INSERT into messages(title, msg, date_start, date_end, app_usersID_FK, date_created, activeflag, msg_status) VALUES (?,?,?,?,?,?,?,?)");

      if(!$stmt){
           throw new Exception("Unable to prepare the statement");
      }

      $dt = date("Y-m-d");
      $stmt->bind_param("ssssisii", $title, $message, $startDate, $endDate, $author, $dt, 1, $status);
      $stmt->execute();

      return true;
 }

Function call

MessageCenter::createMessage("Hello", "Just calling to say hi", "2009-09-12", "2009-09-12", "1", "1");

Error Message is:

Fatal error: Cannot pass parameter 8 by reference

+2  A: 

I'm guessing your bind_param method is actually mysqli_stmt::bind_param. If yes : every parameters (except for the first one) must be variables passed by reference, so they can be "binded".

Like the manual says (emphasis mine) :

mysqli_stmt::bind_param -- mysqli_stmt_bind_param — Binds variables to a prepared statement as parameters


This means you cannot pass a value : you have to use variables.

Si, on your case, something like this should do :

$my_var = 1;
$stmt->bind_param("ssssisii", $title, $message, $startDate, 
   $endDate, $author, $dt, $my_var, $status);
Pascal MARTIN
Nice thorough response
Peter Bailey
@Peter : thanks :-)
Pascal MARTIN
A: 

Found it! It wanted activeFlag to be a variable. The following works:

$dt = date("Y-m-d");
$flag = 1;
$stmt->bind_param("ssssisii", $title, $message, $startDate, $endDate, $author, $dt, $flag, $status);
$stmt->execute();
Scott