This question already has an answer here:
I am trying to get some information to insert into my SQL database using PHP. However, I keep getting that error when trying to do the insert. I have counted and made sure that the data types are correct in my database. I have also counted to make sure nothing extra is being inserted. I cannot seem to figure out how to get this data inserted into my database. Here is the full error message:
mysqli Object ( [affected_rows] => 0 [client_info] => 5.5.42 [client_version] => 50542 [connect_errno] => 0 [connect_error] => [errno] => 0 [error] => [field_count] => 0 [host_info] => Localhost via UNIX socket [info] => [insert_id] => 0 [server_info] => 5.5.60 [server_version] => 50560 [stat] => Uptime: 2086072 Threads: 1 Questions: 1110 Slow queries: 0 Opens: 77 Flush tables: 1 Open tables: 55 Queries per second avg: 0.000 [sqlstate] => 00000 [protocol_version] => 10 [thread_id] => 9123 [warning_count] => 0 ) Inserting Here Whole query INSERT INTO Library
.userdatabase
(idFriendAndFamily
, password
, firstname
, lastname
,phonenumber
, address
, city
, state
, zip
, birthdate
, username
, sex
, relationship
) VALUES('test, bob, saget, 2342134, fakestreet, fakeland,state, 12345, 1234, test, male, friend')
Invalid query: Column count doesn't match value count at row 1
Here is the code I am using to insert with PHP:
switch ($action)
{
case "insert":
echo "Inserting Here ";
$insert = "INSERT INTO `Library`.`userdatabase` (`idFriendAndFamily`, `password`, `firstname`, `lastname`,"
."`phonenumber`, `address`, `city`, `state`, "
."`zip`, `birthdate`, `username`, `sex`, `relationship`) VALUES('$password', '$firstname', "
."$'lastname', '$phonenumber', '$address', '$city',"
."'$state', '$zip', '$birthdate', '$username', '$sex', '$relationship')"; //'N'
$success = $con->query($insert);
if($success == FALSE)
{
$failmess = "Whole query " . $insert . "<br>";
echo $failmess;
die('Invalid query: ' . mysqli_error($con));
} else
{
echo "$insertArray was added <br>";
}
break;
Can anyone see what is going wrong? I have racked my brain over this trying everything I can think of, so any help is appreciated!
</div>