troubleshooting Question

mysql error Column count

Avatar of peter_coop
peter_coopFlag for United Kingdom of Great Britain and Northern Ireland asked on
3 Comments1 Solution385 ViewsLast Modified:
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;

$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);
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros