Page 1 of 1

[SOLVED] Bad query or error: Column count doesn't match valu

Posted: Tue Jul 20, 2004 10:49 am
by mogman42
Ok, I'm using this same basic code syntax with a different database/page and it works fine.

I created a new db/table, ec. for this page data to submit and it gives me this error whenever I try to submit the form.
Bad query or error: Column count doesn't match value count at row 1

Code: Select all

<?php

// Begin submit form variables
$surveyname = $_POST['surveyname'];
$surveyphone = $_POST['surveyphone'];
$surveyemail = $_POST['surveyemail'];
$numcalled = $_POST['numcalled'];
$timecalled = $_POST['timecalled'];
$phoneresolution = $_POST['phoneresolution'];
$helpful = $_POST['helpful'];
$resolution = $_POST['resolution'];
// End submit form variables

// Connect to DB
$link = mysql_connect('localhost','blah','blah') or die ('Could not connect to mySQL: ' .mysql_error() );

// Select Quick Incident DB
$db_selected = mysql_select_db('customer survey', $link) or die ('Could not select DB: ' .mysql_error() );

// Insert form data into DB
mysql_query("INSERT INTO survey (id, surveyname, surveyphone, surveyemail, numcalled, timecalled, phoneresolution, helpful, resolution, submitdate)

VALUES('', '$surveyname', '$surveyphone', '$surveyemail', '$numcalled', '$timecalled', '$phoneresolution', '$helpful', '$resolution', NOW() )")
	or die("Bad query or error: ".mysql_error()); 
mysql_close();

// End insert form data

?>
[/quote]

Posted: Tue Jul 20, 2004 10:52 am
by John Cartwright
I'm assuming your ID is set to auto_increment.

Code: Select all

<?php
// Insert form data into DB 
mysql_query("INSERT INTO survey (id, surveyname, surveyphone, surveyemail, numcalled, timecalled, phoneresolution, helpful, resolution, submitdate) 

VALUES('', '$surveyname', '$surveyphone', '$surveyemail', '$numcalled', '$timecalled', '$phoneresolution', '$helpful', '$resolution', NOW() )") 
   or die("Bad query or error: ".mysql_error()); 
?>
should be

Code: Select all

<?php
// Insert form data into DB 
mysql_query("INSERT INTO survey (surveyname, surveyphone, surveyemail, numcalled, timecalled, phoneresolution, helpful, resolution, submitdate) 

VALUES('$surveyname', '$surveyphone', '$surveyemail', '$numcalled', '$timecalled', '$phoneresolution', '$helpful', '$resolution', NOW() )") 
   or die("Bad query or error: ".mysql_error()); 
?>

Posted: Tue Jul 20, 2004 11:17 am
by mogman42
the reason for the id inclusion was this page that I read....

http://htmlfixit.com/cgi-tutes/tutorial ... _Count.php

Here is what I have right now, and its still generating the error.

Code: Select all

<?php
// Insert form data into DB 
mysql_query("INSERT INTO survey (surveyname, surveyphone, surveyemail, numcalled, timecalled, phoneresolution, helpful, resolution, comments, submitdate) 
	VALUES('$surveyname', '$surveyphone', '$surveyemail', '$numcalled', '$timecalled', '$phoneresolution', '$helpful', '$resolution' '$comments', NOW() )") 
   or die("Bad query or error: ".mysql_error()); 
mysql_close();
// End insert form data

?>

Posted: Tue Jul 20, 2004 11:19 am
by feyd
echo the query string, you may have some invalid data..

Solved!!

Posted: Tue Jul 20, 2004 12:58 pm
by mogman42
solved - had the form type set to submit instead of post :cry: