php/mysql error

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
Cleibe
Forum Newbie
Posts: 5
Joined: Mon Jun 02, 2003 8:35 am

php/mysql error

Post by Cleibe »

Ok. Trying to add info to a mysql db and getting a simple error that's driving me crazy

Column count doesn't match value count at row 1

Here's the table
===========================================
$query = "CREATE table newsletterSurvey
(
ID SMALLINT(4) UNSIGNED NOT NULL AUTO_INCREMENT,
learn TEXT,
frequency TEXT,
length TEXT,
format TEXT,
click TEXT,
interest TEXT,
content_area TEXT,
topics TEXT,
degree TEXT,
classYear TEXT,
school TEXT,
age TEXT,
occupation TEXT,
comments TEXT,
date DATE,

PRIMARY KEY(ID)
)" or die (mysql_error());

$results = mysql_db_query($dbName, $query, $connection);

===============================================
Here is the INSERT statement

$query = "INSERT INTO newsletterSurvey VALUES ( '0',
'".$learn."',
'".$frequency."',
'".$length."',
'".$format."',
'".$click."',
'".$interest."',
'".$content_area."',
'".$topics."',
'".$degree."',
'".$classYear."',
'".$school."'
'".$age."',
'".$occupation."',
'".$comments."'
'".$date."')";

$result = mysql_query($query, $connection) or die(mysql_error());


Any idea??
Tks.
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

quotes man quotes

Post by phpScott »

You are using far to many " a
try this

Code: Select all

$query = "INSERT INTO newsletterSurvey VALUES ( '0',
'$learn',
'$frequency',
'$length',
'$format',
'$click',
'$interest',
'$content_area',
'$topics',
'$degree',
'$classYear',
'$school',
'$age',
'$occupation',
'$comments',
'$date')";
I found what you problem was you missing a couple of comma's at the end of '".$school."' and '".$comments."' which would cause the sql to fail and think that there is less lines than there actually is.

phpScott
Cleibe
Forum Newbie
Posts: 5
Joined: Mon Jun 02, 2003 8:35 am

Post by Cleibe »

Geee...........you're right.
You don't know for how long I've been looking at this code and couldn't see it.
Thanks a lot.
Post Reply