Ovenmit Posted September 30, 2011 Share Posted September 30, 2011 Hi, Im just having some trouble with this...maybe a fresh pair of eyes can help? Im getting a "Warning: mysqli_stmt::bind_param() [mysqli-stmt.bind-param]: Number of elements in type definition string doesn't match number of bind variables" error when I try run this: $date = date("Y-m-d"); $header = $_POST['header']; $summary = $_POST['summary']; $content = $_POST['content']; $query = "INSERT INTO articles (pubdate, title, summary, content) VALUES(?, ?, ?, ?)"; $stmt = $mysqli->stmt_init(); if ($stmt->prepare($query)){ $stmt->bind_param('i,s,s,s', $date, $header, $summary, $content); $stmt->execute(); $stmt->close(); } else { echo "ERROR: SQL statement failure!"; echo "<a href='addnews.php'> -> OK</a>"; } $mysqli->close(); It looks fine to me, just can't see whats wrong lol! Link to comment https://forums.phpfreaks.com/topic/248162-mysql-insert-prepared-statement-whats-wrong/ Share on other sites More sharing options...
voip03 Posted September 30, 2011 Share Posted September 30, 2011 Why '?' $query = "INSERT INTO articles (pubdate, title, summary, content) VALUES(?, ?, ?, ?)"; Link to comment https://forums.phpfreaks.com/topic/248162-mysql-insert-prepared-statement-whats-wrong/#findComment-1274330 Share on other sites More sharing options...
Ovenmit Posted September 30, 2011 Author Share Posted September 30, 2011 Why '?' $query = "INSERT INTO articles (pubdate, title, summary, content) VALUES(?, ?, ?, ?)"; Not sure how to answer... because I wanted to use a prepared statement? Are you saying I should just go with a straight query? ie: $query = "INSERT INTO articles (pubdate, title, summary, content) VALUES('$date', '$header', '$summary', '$content')"; Link to comment https://forums.phpfreaks.com/topic/248162-mysql-insert-prepared-statement-whats-wrong/#findComment-1274333 Share on other sites More sharing options...
voip03 Posted September 30, 2011 Share Posted September 30, 2011 can you try it Link to comment https://forums.phpfreaks.com/topic/248162-mysql-insert-prepared-statement-whats-wrong/#findComment-1274337 Share on other sites More sharing options...
Buddski Posted September 30, 2011 Share Posted September 30, 2011 You are separating the types field when you shouldn't be, Try this. $stmt->bind_param('isss', $date, $header, $summary, $content); Edit: In fact, you should be using 'ssss' because the $date variable is not an integer. Link to comment https://forums.phpfreaks.com/topic/248162-mysql-insert-prepared-statement-whats-wrong/#findComment-1274352 Share on other sites More sharing options...
Ovenmit Posted September 30, 2011 Author Share Posted September 30, 2011 Sorry, had to step out and see a client. Running it as a straight query works. You are separating the types field when you shouldn't be, Try this. $stmt->bind_param('isss', $date, $header, $summary, $content); Edit: In fact, you should be using 'ssss' because the $date variable is not an integer. Thanks a bunch, that was the problem lol, 'ssss' instead of 'i,s,s,s'. Stupid mistake on my part and thanks for the date tip. - SOLVED - Link to comment https://forums.phpfreaks.com/topic/248162-mysql-insert-prepared-statement-whats-wrong/#findComment-1274399 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.