Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Error Message On Add New Record

Posted on 2015-01-31
6
Medium Priority
?
67 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 111

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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

671 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