I have stared the work to insert the data in the database from php file. Database connection is established successfully but data is not inserted in the database. Some sort of error like "Error: Column count doesn't match value count at row 1" occurs.
Our database name is request_license, table name is user_data and the field names in the database are First_Name, Last_Name, Name_Of_Organization, Email, Contact_number, Duration_In_Years, MAC_Address, CPU_ID, Motherboard_ID
php code

$con = mysql_connect("localhost","root","");
if (!$con)
  die('Could not connect: ' . mysql_error());

mysql_select_db("request_license", $con);
echo   "connection establish";

$sql="INSERT INTO user_data (First_Name, Last_Name, Name_Of_Organization,Email,Contact_number,Duration_In_Years,MAC_Address,CPU_ID,Motherboard_ID)

if (!mysql_query($sql,$con))
  die('Error: ' . mysql_error());
echo "1 record added";


html code

<body bgcolor="#FFB6C1">
<form action="insert.php" method="post">
<font size="15" face="Monotype Corsiva" color="black">
<center>ID Technologies</center></font></h1>


     <td width="50%"> First Name: </td> 
     <td> <input type="text" name="fname" /> </td>
      <td width="50%"> Last Name :</td> 
      <td> <input type="text" name="lname" /></td>

      <td width="50%"> Organization Name:</td>
      <td> <input type="text" name="oname"/></td>

        <td width="50%">Email:</td> 
        <td><input type="text" name="email" /></td>


   <td width="50%">Contact Number:</td>
   <td><input type="text" name="cno" /></td>

<td width="50%">Duration in years:</td>
<td><input type="text" name="years"/ ></td>

<input type="radio"/>Extend<br/>
<input type="radio"/>Read Only<br/><br/>


<a href="application.exe">Download link</a>


   <td width="50%">MAC ID:</td>
   <td><input type="text" name="mid" /></td>


   <td width="50%">CPU ID:</td>
   <td><input type="text" name="cid" /></td>


   <td width="50%">MotherBoard ID:</td>
   <td><input type="text" name="mbid" /></td>

<input type="submit" value="Submit Data"/>



Please help me why this error occurs.....

Recommended Answers

All 5 Replies

As the error says, the columns specified in the insert query doesn't match with the values you are passing.
Please check that you have all the columns in your table with same name.
always try to echo the query & run in mysql

For ex:INSERT INTO `soc`.`sks_color` (`id`, `name`, `desc`) VALUES (NULL, 'blue', 'as sky color ');
run in my sql & u easily find the error

May be the comma (,) is missing between these columns in query $_POST[years] and $_POST[mid]!

ohhh thanxxx alot ......actually comma was missing......

I think its better to mark it as solved :)

When ever u find query problem always echo query. In your case echo $sql in phpmyadmin
you will get error through which u can come to know what is wrong in your quety.

Also check all fields in table which u want to insert.

Enjoy Coding :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.