SQL Error! Please help

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
urb
Forum Newbie
Posts: 21
Joined: Fri Nov 08, 2002 1:08 am
Location: Los Angeles, California

SQL Error! Please help

Post by urb »

When Im trying to add data into a table I get this error :( . Can anyone please help?


"Column count doesn't match value count at row 1"



Thanks,

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

please post

Post by phpScott »

Please post the sql query you are trying to submit.

As the error says the number of items you are trying to submit doesn't match the number of columns in your table.

They have to match, but that depends on the style of query your are trying to submit.

phpScott
urb
Forum Newbie
Posts: 21
Joined: Fri Nov 08, 2002 1:08 am
Location: Los Angeles, California

Post by urb »

I am trying to add text from 3 fields into a table with 4 fields. The first being set to primary ' id ' and the rest from text fields from forms.

sql code

$sql = "INSERT INTO resources (id, res_name, res_url, res_desc)
VALUES ('$_POST[res_name]', '$_POST[res_url]', '$_POST[res_desc]')";



- Matt
urb
Forum Newbie
Posts: 21
Joined: Fri Nov 08, 2002 1:08 am
Location: Los Angeles, California

Post by urb »

I figured it out. It was that damm ID tag in the sql statement.


Thanks for the help phpScott.

- Matt Urban
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

try this

Post by phpScott »

$sql = "INSERT INTO resources (id, res_name, res_url, res_desc)
VALUES ('$_POST[res_name]', '$_POST[res_url]', '$_POST[res_desc]')";
Is almost correct. If id is discribed as an auto_increment value in your table you still need to put in the spot for it in your insert statement.
This correction should work.

Code: Select all

$sql = "INSERT INTO resources (id, res_name, res_url, res_desc) 
VALUES ('','$_POSTїres_name]', '$_POSTїres_url]', '$_POSTїres_desc]')";
phpScott
Post Reply