Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 07-26-2004, 10:25 PM   #1
Member (10 bit)
 
GSXdan's Avatar
 
Join Date: Jun 2002
Location: P-burg, Ohio, USA
Posts: 555
Send a message via AIM to GSXdan
php/mySQL error...

I am getting this error when running my address book script(see below):

Column count doesn't match value count at row 1

I have 6 tables in my mySQL database: master_name, address, telephone, fax, email, and personal_notes. When running the script, the first and last name will be entered into the database, but nothing else will. Sorry i dont have it working online, I cant figure out how to connect to my mySQL database on netfirms Let me know if you need any other info.

Thanks ^dan
Attached Files
File Type: zip addressbook.zip (1.6 KB, 21 views)
GSXdan is offline   Reply With Quote
Old 07-27-2004, 07:22 AM   #2
Staff
Premium Member
 
mairving's Avatar
 
Join Date: Jul 1999
Location: Arlington, TN
Posts: 5,538
That error is caused because you are posting too few values for the columns. For instance, if you have 8 columns in your table and you only insert 7 and don't tell MySQL that, you will get this error.

I generally always like to specify what data is going in what column. It makes sure that the right data goes into the right column and you can avoid things like this. Something like so:

Old Code:
PHP Code:
$add_address "INSERT INTO address VALUES ('', $master_id,
                             now(), now(), '$_POST[address]', '$_POST[city]',
                             '$_POST[state]', '$_POST[zipcode]', '$_POST[add_type]')"

New Code:
PHP Code:
$add_address "INSERT INTO address ";
$add_address .= "(fieldname1, fieldname2, fieldname3, fieldname4, ";
$add_address .= "fieldname5, fieldname6, fieldname7, fieldname8) ";
$add_address .= "VALUES ('', $master_id, now(), now(), ";
$add_address .= "'$_POST[address]', '$_POST[city]', ";
$add_address .= "'$_POST[state]', '$_POST[zipcode]', '$_POST[add_type]')"
Note that if you have an auto_increment field in fieldname1 instead of having a blank value, you can just bypass the value like so:
PHP Code:
$add_address "INSERT INTO address ";
$add_address .= "(fieldname2, fieldname3, fieldname4, ";
$add_address .= "fieldname5, fieldname6, fieldname7, fieldname8) ";
$add_address .= "VALUES ($master_id, now(), now(), ";
$add_address .= "'$_POST[address]', '$_POST[city]', ";
$add_address .= "'$_POST[state]', '$_POST[zipcode]', '$_POST[add_type]')"
I also concatenated the add_address variable to make it more readable.
__________________

Want to Make $$$$ with your Computer? No Risk! Simply press shift-4 four times in a row
mairving is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 06:50 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2