This question already has an answer here:
So far I have created the table and getting a successful message. However when I go to insert into the table, I get: Error inserting sample record into 'Users': Column count doesn't match value count at row 1.
This is the code for creating the table:
mysql_select_db($dbName, $dbConnection);
$sql = "CREATE TABLE ".$dbTable." (ID int(6) auto_increment NOT NULL, Username varchar(20) NOT NULL, Password varchar(20) NOT NULL, UserType int(1) NOT NULL, FirstName varchar(15) NOT NULL, LastName varchar(15) NOT NULL, DOB DATETIME NOT NULL, Phone varchar(15) NOT NULL, Department varchar(15),PRIMARY KEY(ID))";
if(mysql_query($sql, $dbConnection))
{
echo("Table '".$dbTable."' created<br />");
}
else
{
echo("Error creating table '".$dbTable."': ".mysql_error()."<br />");
}
And this is the code for inserting:
$sql = "INSERT INTO ".$dbTable." (Username, Password, UserType, FirstName, LastName, DOB, Department) VALUES (1, 'admin', 'admin', 1, 'Admin', 'Admin', '1900-01-01', '12345656', 'IT')";
if(mysql_query($sql, $dbConnection))
{
echo("Added sample record to '".$dbTable."' table<br />");
}
else
{
echo("Error inserting sample record into '".$dbTable."': ".mysql_error()."<br />");
}
</div>