0

I've been working on a basic forum for our site. I've ran into some trouble with a query using PDO with the error:

 number of bound variables does not match number of tokens

This is caused by this fllowing code:

$stmt1 = $conn->prepare("UPDATE topics SET replies=:replies, lastposter=:poster, lastpostdate=:date WHERE id = :id"); 
$stmt1->bindParam(':id', $id);
$stmt1->bindParam(':replies', $replies);
$stmt1->bindParam(':poster', $poster);
$stmt1->bindParam(':date', $date);
$stmt1->execute();

$id, $replies and $date are integers, $poster is a string. I have a similar query above that works just fine which is as follows:

 $stmt1 = $conn->prepare("UPDATE main SET topics = :topics, lastposter = :poster, lastpostdate = :date WHERE id = :id"); 
rtruszk
  • 3,902
  • 13
  • 36
  • 53
user1372896
  • 542
  • 1
  • 10
  • 27
  • What is the schema of your topics table? – Davide Pastore Jun 25 '15 at 23:01
  • `id` int(11) unsigned NOT NULL auto_increment, `forumid` int(11) unsigned, `message` text NOT NULL, `subject` text NOT NULL, `poster` text NOT NULL, `date` int(11) NOT NULL, `lastposter` varchar(200) NOT NULL, `lastpostdate` int(11) NOT NULL, `replies` int(11) unsigned NOT NULL, – user1372896 Jun 25 '15 at 23:19
  • Did you cut and paste the code exactly from your script? I don't see a problem in the code in the question. This error means that there's a mismatch between the placeholders in the prepared statement and the ones that you bound with `bindParam` -- check your code for typos. – Barmar Jun 25 '15 at 23:28
  • As far as I'm aware yes, all the vars are correct same with the sql parts – user1372896 Jun 25 '15 at 23:52
  • Just went through every var and bindparam and they all match the SQL and each other. Is there anyway I can see exactly which one is causing the error? The exact error I'm getting is Error: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens – user1372896 Jun 26 '15 at 00:22

0 Answers0