Link to home
Start Free TrialLog in
Avatar of DS928
DS928Flag for United States of America

asked on

Error Message On Add New Record

I am getting this error message when I try to add a new record.
"Column count doesn't match value count at row 1"

<?php
		  include("7conn.php");
		  $mode=$_GET["mode"];
		  if($mode=="add") {
		  	$recordCust=$_POST["recordCust"];
			$recordSite=$_POST["recordSite"];
			$recordUser=$_POST["recordUser"];
			$recordPass=$_POST["recordPass"];
			$sql="insert into records(record,Cust,recordSite,recordUser, recordPass, recordDateAdded) values(" . $_SESSION['clientID'] . "'$recordSite','$recordUser','$recordPass', Now())";
			$result=mysql_query($sql,$connection) or die(mysql_error());
			header("location: clientlogin.php");
		  } elseif($mode=="update") {
		  	$recordSite=$_POST["recordSite"];
			$recordUser=$_POST["recordUser"];
			$recordPass=$_POST["recordPass"];
			$recordId = $_POST["recordId"];
			$sql="update records set recordSite='$recordSite',recordUser='$recordUser',recordPass='$recordPass'  where recordId='$recordId'";
			//echo $sql;
			$result=mysql_query($sql,$connection) or die(mysql_error());
    		header("location: clientlogin.php");
		  }
?>

Open in new window

Avatar of Marco Gasi
Marco Gasi
Flag of Spain image

You are passing 6 columns and only 5 values.
record                                
Cust                                      $_SESSION['clientID']
recordSite                           $recordSite
recordUser                         $recordUser
recordPass                         $recordPass
recordDateAdded             Now()

Probably record is auto_increment, so you can just drop it from the query and this will work. Otherwise you have to provide a value for record column.
This line appears to be missing a comma after the session data:

$sql="insert into records(record,Cust,recordSite,recordUser, recordPass, recordDateAdded) values(" . $_SESSION['clientID'] . "'$recordSite','$recordUser','$recordPass', Now())";

Open in new window


You might also want to learn about how to escape the input data before using it in a query.  And, not a minute too soon, PHP is doing away with support for the MySQL extension, so you would want to avoid writing code that you know is obsolete.  It would be a better choice to drop MySQL and move to one of the supported extensions.
Avatar of DS928

ASKER

I updated this and still getting an error message.
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''66','66','66', Now())' at line 1"

<?php
//set_error_handler("var_dump");
		  include("7conn.php");
		  $mode=$_GET["mode"];
		  if($mode=="add") {
		  	$recordCust=$_POST["recordCust"];
			$recordSite=$_POST["recordSite"];
			$recordUser=$_POST["recordUser"];
			$recordPass=$_POST["recordPass"];
			$sql="insert into records(recordCust,recordSite,recordUser, recordPass, recordDateAdded) values(" . $_SESSION['clientID'] . ",'$recordSite','$recordUser','$recordPass', Now())";
			$result=mysql_query($sql,$connection) or die(mysql_error());
			header("location: clientlogin.php");
		  } elseif($mode=="update") {
		  	$recordSite=$_POST["recordSite"];
			$recordUser=$_POST["recordUser"];
			$recordPass=$_POST["recordPass"];
			$recordId = $_POST["recordId"];
			$sql="update records set recordSite='$recordSite',recordUser='$recordUser',recordPass='$recordPass'  where recordId='$recordId'";
			//echo $sql;
			$result=mysql_query($sql,$connection) or die(mysql_error());
    		header("location: clientlogin.php");
		  }
?>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Marco Gasi
Marco Gasi
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DS928

ASKER

Thank you that worked!