Page 1 of 1

Insert Into Table...weird error

Posted: Tue Mar 17, 2009 3:35 pm
by nishmgopal
Hi guys, I am trying to insert some fields into my table, and I am getting the following error:

Column count doesn't match value count at row 4

Here is my code:

Code: Select all

 
 
  <?php
  session_start();
if(isset($_SESSION['Job_ID']))
 {
  echo $_SESSION['Job_ID'];
 }
else { echo 'Job ID Not Set.';}
?>
 
$skill1 = $_POST['skill1'];
$weight1 = $_POST['weight1'];
$skill2 = $_POST['skill2'];
$weight2 = $_POST['weight2'];
$skill3 = $_POST['skill3'];
$weight3 = $_POST['weight3'];
$skill4 = $_POST['skill4'];
$weight4 = $_POST['weight4'];
$skill5 = $_POST['skill5'];
$weight5 = $_POST['weight5'];
$skill6 = $_POST['skill6'];
$weight6 = $_POST['weight6'];
 
 
if (isset($_POST['addmore'])) {
# THIS CODE TELL MYSQL TO INSERT THE DATA FROM THE FORM INTO YOUR MYSQL TABLE
 
$sql = "INSERT INTO conmg.ID_Table (ID, Job_ID, Skill_Name, Weight) VALUES ('', '$_SESSION[Job_ID]', '$skill1', '$weight1'),('', '$_SESSION[Job_ID]', '$skill2', '$weight2'), ('', '$_SESSION[Job_ID]', '$skill3', '$weight3'), ('', '$_SESSION[Job_ID]' '$skill4', '$weight4'), ('', '$_SESSION[Job_ID]', '$skill5', '$weight5'), ('', '$_SESSION[Job_ID]', '$skill6', '$weight6')";
 
 
if($result = mysql_query($sql)) {
echo "The Project Database has been Updated";
} else {
echo "ERROR: ".mysql_error();
}
} 
 
?>
 
Can anyone help?

Re: Insert Into Table...weird error

Posted: Tue Mar 17, 2009 4:07 pm
by JeffG
nishmgopal wrote:Can anyone help?
You could probably more easily help yourself by adding the statement

Code: Select all

 
echo "$sql<br>";
 
before the line with the mysql_query to see what exactly has been generated for your sql statement. I can't guess at what all those $_POSTs are returning.

(Or at least output $sql in your ERROR: statement - mysql_error() on its own is only going to tell you what the error is, not what caused it.)

Re: Insert Into Table...weird error

Posted: Wed Mar 18, 2009 9:59 am
by mmoussa
nishmgopal wrote:Hi guys, I am trying to insert some fields into my table, and I am getting the following error:

Column count doesn't match value count at row 4
You're missing a comma between two values you are trying to insert in the 4th row. See below.

Original:

Code: Select all

 
$sql = "INSERT INTO conmg.ID_Table (ID, Job_ID, Skill_Name, Weight) VALUES ('', '$_SESSION[Job_ID]', '$skill1', '$weight1'),('', '$_SESSION[Job_ID]', '$skill2', '$weight2'), ('', '$_SESSION[Job_ID]', '$skill3', '$weight3'), ('', '$_SESSION[Job_ID]' '$skill4', '$weight4'), ('', '$_SESSION[Job_ID]', '$skill5', '$weight5'), ('', '$_SESSION[Job_ID]', '$skill6', '$weight6')";
How to fix:

Code: Select all

 
$sql = "INSERT INTO conmg.ID_Table (ID, Job_ID, Skill_Name, Weight) VALUES ('', '$_SESSION[Job_ID]', '$skill1', '$weight1'),('', '$_SESSION[Job_ID]', '$skill2', '$weight2'), ('', '$_SESSION[Job_ID]', '$skill3', '$weight3'), ('', '$_SESSION[Job_ID]' [b][color=#008000]--> comma goes here <--[/color][/b] '$skill4', '$weight4'), ('', '$_SESSION[Job_ID]', '$skill5', '$weight5'), ('', '$_SESSION[Job_ID]', '$skill6', '$weight6')";