Solved

Error Message On Add New Record

Posted on 2015-01-31
6
61 Views
Last Modified: 2015-01-31
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

0
Comment
Question by:DS928
  • 3
  • 2
6 Comments
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 40581663
You are passing 6 columns and only 5 values.
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 40581666
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.
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 40581793
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.
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:DS928
ID: 40581870
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

0
 
LVL 31

Accepted Solution

by:
Marco Gasi earned 500 total points
ID: 40581920
Try adding quotes to $_SESSION['clientID']

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

Open in new window

0
 

Author Closing Comment

by:DS928
ID: 40581935
Thank you that worked!
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now