ERROR:Column count doesn't match value count at row 1
Posted: Wed Aug 19, 2009 7:34 am
Hi,
As i want to insert a record from the form and i have created a form. i have also tested the connection string. its working properly. but when i want to insert a record the following error persists. Can anyone solve this puzzle.
Code:
As i want to insert a record from the form and i have created a form. i have also tested the connection string. its working properly. but when i want to insert a record the following error persists. Can anyone solve this puzzle.
Code:
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<form action="test.php" method="post">
ID: <input type="text" name="id_form" /><br>
NAME: <input type="text" name="name_form" /><br>
YEAR: <input type="text" name="year_form" /><br>
<input type="submit" />
</form>
<body>
<?php
//connection parameters
$username = "root";
$password = "";
$dbhost = "localhost";
//connection to database
$dbconnection = mysql_connect($dbhost, $username, $password) or die("Could not connect to MySQL Database");
echo "Connection Success!!!";
echo "<br/>";
//working with particular database
$dbhandle = mysql_select_db("test", $dbconnection) or die("Could not select the test database");
echo "The test database is selected";
echo "<br/>";
$query = "INSERT INTO cars (id, name, year)
VALUES
('$_POST[id_form]', $_POST[name_form]', $_POST[year_form]')";
if(!mysql_query($query, $dbconnection))
{
die('ERROR:'.mysql_error());
}
echo "1 record(s) added";
?>
</body>
</html>