TABLE COLUMNS theid sirename yob color breed owner approved
FORM TO GATHER INFO TO INSERT INTO DB
<form method='post' action='nominateasire2.php'>
The ID: <input type='text' name='theid'><br><br>
Sire Name: <input type='text' name='sirename'><br><br>
YOB: <input type='text' name='yob'><br><br>
Color: <input type='text' name='color'><br><br>
Breed: <input type='text' name='breed'><br><br>
Owner: <input type='text' name='owner'><br><br>
<input type='submit' value='Nominate'>
</form>
PHP TO INSERT INFO FROM FORM INTO DB
$sql="INSERT INTO nominatedsires (theid,sirename,yob,color,breed,owner,approved)
VALUES ('$_POST[theid]','$_POST[sirename]','$_POST[yob]',
'$_POST[color]','$_POST[breed]','$_POST[owner]','$_POST[owner]','no')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo "1 record added";
When using the form I get the error Column count doesn't match value count at row 1. When I go through PHPmyAdmin and input the data it all works fine so there isn't an error on the backend (value length/type/etc.) I can't figure out what the issue with my code is. Any help greatly appreciated!
mysqli
you should be using parameterized queries andbind_param
to add user data to your query. Avoid using string interpolation to accomplish this. Adding$_POST
data directly to a query is extremely dangerous. – tadman Feb 5 at 20:11