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

<?php
$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)
VALUES
('$_POST[fname]','$_POST[lname]','$_POST[Oname]','$_POST[email]','$_POST[cno]','$_POST[years]''$_POST[mid]','$_POST[cid]','$_POST[mbid]')";

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

mysql_close($con)
?>

html code

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

<form>
<table>

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

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

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

<tr>

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

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

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


<table>

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

<tr>

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

<tr>

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

<tr>

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

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

</form>


</body>
</html>

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

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, networking, learning, and sharing knowledge.