Page 1 of 1

ERROR:Column count doesn't match value count at row 1

Posted: Wed Aug 19, 2009 7:34 am
by phphunger
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:

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>
 

Re: ERROR:Column count doesn't match value count at row 1

Posted: Wed Aug 19, 2009 7:35 am
by papa
What does your mysql table look like ?

Re: ERROR:Column count doesn't match value count at row 1

Posted: Wed Aug 19, 2009 7:53 am
by mrvijayakumar
Hi,
Replace this code and try. Reply me once work get done or any error occurs.

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="" 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" name="submit" />
    </form>
    <body>
 
        <?php
   if(isset($_REQUEST['submit'])) {
            //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>

Re: ERROR:Column count doesn't match value count at row 1

Posted: Thu Aug 20, 2009 12:30 am
by phphunger
Hi,

the code is working. thanks for your contribution.

Re: ERROR:Column count doesn't match value count at row 1

Posted: Thu Aug 20, 2009 12:32 am
by mrvijayakumar
Welcome..