i'm trying to insert a POST array consisting in 8 fields to a mysql table of 8 columns. But i'm getting this error when submitting the form:
Error: Column count doesn't match value count at row 1
When i search this error says the data passed doesn't fit in the column count of the database table, but the table has 8 columns. What i'm doing wrong?.
Here's my code:
<html>
<body>
<form action="" method="post">
Nombre: <input type="text" name="data[]">
Apellido: <input type="text" name="data[]"></br>
Direccion: <input type="text" name="data[]"></br>
Telefono: <input type="text" name="data[]">
Telefono 2: <input type="text" name="data[]"></br>
Email: <input type="text" name="data[]"></br>
Edad: <input type="text" name="data[]"></br>
Foto: <input type="text" name="data[]">
<input type="submit">
</form>
<?php
$con=mysql_connect("localhost","root","");
if (!$con){ die('Could not connect: ' . mysql_error()); }
mysql_select_db("ag_online", $con);
foreach($_POST['data'] as $d ){
$sql = "INSERT INTO `contacts` VALUES ('', '".$d."');";
mysql_query( $sql );
}
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con);
?>
</body>
</html>