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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mogman42
Forum Newbie
Posts: 18
Joined: Fri May 21, 2004 10:00 am

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

Post 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]
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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()); 
?>
mogman42
Forum Newbie
Posts: 18
Joined: Fri May 21, 2004 10:00 am

Post 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

?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

echo the query string, you may have some invalid data..
mogman42
Forum Newbie
Posts: 18
Joined: Fri May 21, 2004 10:00 am

Solved!!

Post by mogman42 »

solved - had the form type set to submit instead of post :cry:
Post Reply