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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phphunger
Forum Commoner
Posts: 45
Joined: Tue Aug 11, 2009 11:56 pm

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

Post 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>
 
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

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

Post by papa »

What does your mysql table look like ?
User avatar
mrvijayakumar
Forum Commoner
Posts: 58
Joined: Tue Aug 18, 2009 12:39 am
Location: Chennai city, India
Contact:

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

Post 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>
phphunger
Forum Commoner
Posts: 45
Joined: Tue Aug 11, 2009 11:56 pm

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

Post by phphunger »

Hi,

the code is working. thanks for your contribution.
User avatar
mrvijayakumar
Forum Commoner
Posts: 58
Joined: Tue Aug 18, 2009 12:39 am
Location: Chennai city, India
Contact:

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

Post by mrvijayakumar »

Welcome..
Post Reply