Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
urb
Forum Newbie
Posts: 21 Joined: Fri Nov 08, 2002 1:08 am
Location: Los Angeles, California
Post
by urb » Fri Nov 08, 2002 1:08 am
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
phpScott
DevNet Resident
Posts: 1206 Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.
Post
by phpScott » Fri Nov 08, 2002 1:11 am
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 » Fri Nov 08, 2002 1:15 am
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 » Fri Nov 08, 2002 1:17 am
I figured it out. It was that damm ID tag in the sql statement.
Thanks for the help phpScott.
- Matt Urban
phpScott
DevNet Resident
Posts: 1206 Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.
Post
by phpScott » Fri Nov 08, 2002 2:45 am
$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