0

I am receiving 2 errors in my code below:

Warning: mysqli::prepare() [mysqli.prepare]: (21S01/1136): Column count doesn't match value count at row 1 in ... on line 115

Fatal error: Call to a member function bind_param() on a non-object in ... on line 119

I am using mysqli and php code. What do I need to do in order to fix these errors?

CODE:

$insertsql = "
INSERT INTO Teacher
(TeacherForename, TeacherSurname, TeacherEmail, TeacherAlias, TeacherUsername, TeacherPassword, Code)
VALUES
(?, ?, ?, ?, ?, ?, ?, ?)
";
if (!$insert = $mysqli->prepare($insertsql)) {
// Handle errors with prepare operation here
}                                           

$insert->bind_param("sssssss", $getfirstname, $getsurname,
         $getemail, $getid, $getuser,
         $teacherpassword, $code);

$insert->execute();

if ($insert->errno) {
// Handle query error here
}

$insert->close();
Dharman
  • 30,962
  • 25
  • 85
  • 135
user1394925
  • 754
  • 9
  • 28
  • 51
  • 1
    You have 7 parameters, and 8 `?` in the VALUES; delete one of the `?`, and see if that makes both messages go away.... – andrewsi Aug 24 '12 at 20:37
  • @andrewsi I thought I removed the ? but I can clearly see I havn't. Sorry and thanks for your comment :) – user1394925 Aug 24 '12 at 20:41
  • @jprofitt - that's how mysqli deals with bound parameters - http://php.net/manual/en/mysqli-stmt.bind-param.php – andrewsi Aug 24 '12 at 20:42
  • @andrewsi You are absolutely correct. Been working in PDO-land for too long! – jprofitt Aug 24 '12 at 23:13

1 Answers1

0

You have too many parameters in your SQL:

INSERT INTO Teacher 
    (TeacherForename, TeacherSurname, TeacherEmail, TeacherAlias, TeacherUsername,   
    TeacherPassword, Code)
VALUES
    (?, ?, ?, ?, ?, ?, ?, ?)

There are 7 columns and 8 parameters.

andrewsi
  • 10,807
  • 132
  • 35
  • 51