peter_coop
asked on
mysql error Column count
hello
i am getting this error when i run this query:
mysql error Column count doesn't match value count at row 1
i have tried to find error but cannot seem to correct it. could someone point out my mistake? many thanks
i am getting this error when i run this query:
mysql error Column count doesn't match value count at row 1
i have tried to find error but cannot seem to correct it. could someone point out my mistake? many thanks
function runSQL($rsql) {
$hostname = "localhost";
$username = "root";
$password = "";
$dbname = "sample";
$connect = mysql_connect($hostname,$username,$password) or die ("Error: could not connect to database");
$db = mysql_select_db($dbname);
$result = mysql_query($rsql) or die ('mysql error ' . mysql_error() . ' in query ' . $rsql);
return $result;
mysql_close($connect);
}
$dept = array();
$box = array();
while ($row = mysql_fetch_array($result)) {
$dept[] = $row['department'];
$box[] = $row['custref'];
}
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
header("Cache-Control: no-cache, must-revalidate" );
header("Pragma: no-cache" );
header("Content-type: application/json");
$json = "";
$json .= "{\n";
$json .= "dept: [\"". implode('","', $dept). "\"],\n";
$json .= "box: [\"". implode('","', $box) ."\"]\n";
$json .= "}\n";
echo $json;
$sql = "INSERT INTO `act` (department, item) VALUES ('". implode("'),('", $dept) . "'),('" . implode("'),('", $box) . "')";
$result = runSQL($sql);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
excellent. thanks very much
However the error suggests this isn't happening,
If you echo out $rsql in your runSQL() function you'll see the problem.
You are trying to insert more values into a row then there are columns.