Solved

Error Message On Add New Record

Posted on 2015-01-31
6
66 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 110

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

622 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