Jump to content
Larry Ullman's Book Forums

Recommended Posts

Hi all.

I'm being working on an insert query using prepare statement to store information retrieve from the user. this are the query that i'm using.

$q = " INSERT INTO author(author_name) VALUES(?)";
$stmt = mysqli_prepare($dbc, $q);
mysqli_stmt_bind_param($stmt,'s', $author);
$author_id = mysqli_insert_id($dbc);

//            //                 //         //         
$q = " INSERT INTO categories( category_name) VALUES(?)";
$stmt = mysqli_prepare($dbc, $q);
mysqli_stmt_bind_param($stmt, 's', $category);
$category_id = mysqli_insert_id($dbc);


///        ///                ///              ///
$q = "INSERT INTO titles(title, user_id, category_id) VALUES(?,?,?)";
$stmt = mysqli_prepare($dbc, $q);
mysqli_stmt_bind_param($stmt,'s,i,i', $title, $user_id, $category_id);                  //Line 289
mysqli_stmt_execute($stmt) or die ("Error: " . mysqli_stmt_error($stmt) );            
$title_id = mysqli_insert_id($dbc);

 

 

For me everything look fine, but i getting the following error.

 

Warning: mysqli_stmt_bind_param() [function.mysqli-stmt-bind-param]: Number of elements in type definition string doesn't match number of bind variables inC:\xampp\htdocs\index2\user_php\upload.php on line 289Error: No data supplied for parameters in prepared statement

Can any one tell me what i doing wrong here. I suspect that mysqli_insert_id is causing the problem because i might no generating a id yet since the statement get execute down further the script.

 

 

Link to comment
Share on other sites

 Share

×
×
  • Create New...