Solved

Error Message On Add New Record

Posted on 2015-01-31
6
59 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 30

Expert Comment

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

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 108

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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

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 30

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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 …

744 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

12 Experts available now in Live!

Get 1:1 Help Now