DS928
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"
"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");
}
?>
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.
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:
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.
$sql="insert into records(record,Cust,recordSite,recordUser, recordPass, recordDateAdded) values(" . $_SESSION['clientID'] . "'$recordSite','$recordUser','$recordPass', Now())";
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.
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"
"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");
}
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you that worked!