Lost Password?


Go Back   CodeCall Programming Forum > Web Development Forum > PHP Forum

PHP Forum Use this forum to discuss all aspects of PHP Development. PHP is a server-side, cross-platform, HTML embedded scripting language that lets you create dynamic web pages.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-01-2008, 11:56 PM
shiyam198 shiyam198 is offline
Newbie
 
Join Date: Sep 2008
Posts: 11
Rep Power: 0
shiyam198 is on a distinguished road
Default Column count doesn't match value count at row 1

Dear Guys,

When I am doing an "INSERT" in a PHP file, i am getting an error

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

Normally it comes when the number of column names in a SQL query does not match the number of values we pass in that query.

I made sure it is the case, and i am still getting this error.

My Insert statement
--------------------
PHP Code:
mysql_query("INSERT INTO lk_contact(fname,lname,title,company,worktel1,worktel2,worktel3,workfax,workadd,mobtel1,mobtel2,mobtel3,hometel1,hometel2,hometel3,homeadd,email,webpage,comments,bday,afname,alname,aemail,awrkno,lkgroup) VALUES('$_POST[fname]'),('$_POST[lname]'),('$_POST[title]'),('$_POST[company]'),('$_POST[worktel1]'),('$_POST[worktel2]'),('$_POST[worktel3]'),('$_POST[workfax]'),('$_POST[workadd]'),('$_POST[mobtel1]'),('$_POST[mobtel2]'),('$_POST[mobtel3]'),('$_POST[hometel1]'),('$_POST[hometel2]'),('$_POST[hometel3]'),('$_POST[homeadd]'),('$_POST[email]'),('$_POST[webpage]'),('$_POST[comments]'),('$_POST[bday]'),('$_POST[afname]'),('$_POST[alname]'),('$_POST[aemail]'),('$_POST[awrkno]'),('$_POST[lkgroup]')")
or die(
mysql_error()); 
Just incase, you are intersested - THE TABLE
--------------------------------------------

CREATE TABLE lk_contact(
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
fname VARCHAR(30),
lname VARCHAR(30),
title VARCHAR(50),
company VARCHAR(20),
worktel1 VARCHAR(20),
worktel2 VARCHAR(20),
worktel3 VARCHAR(20),
workfax VARCHAR(20),
workadd VARCHAR(20),
mobtel1 VARCHAR(20),
mobtel2 VARCHAR(20),
mobtel3 VARCHAR(20),
hometel1 VARCHAR(20),
hometel2 VARCHAR(20),
hometel3 VARCHAR(20),
homeadd VARCHAR(100),
email VARCHAR(40),
webpage VARCHAR(150),
comments VARCHAR(400),
bday VARCHAR(20),
afname VARCHAR(20),
alname VARCHAR(20),
aemail VARCHAR(20),
awrkno VARCHAR(20),
lkgroup VARCHAR(20));

Please, if you find any thing wrong here, please let me know.. 3 hours of trying different things. No luck.

Thanks for your Time.

Regards.
Shiyam

Last edited by Jaan; 09-02-2008 at 01:10 AM. Reason: Please use code tags when you're posting your codes!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 09-02-2008, 01:15 AM
Jaan's Avatar   
Jaan Jaan is offline
Mod
 
Join Date: Dec 2006
Location: Estonia
Age: 17
Posts: 930
Last Blog:
AdStar Ad Control Pa...
Rep Power: 16
Jaan is a jewel in the roughJaan is a jewel in the roughJaan is a jewel in the roughJaan is a jewel in the rough
Send a message via MSN to Jaan
Default Re: Column count doesn't match value count at row 1

correct syntax is:

PHP Code:
mysql_query("INSERT INTO table_name (column1, column2, column3) VALUES ('value1', 'value2', 'value3')"); 
__________________


Cheap & Professional Web Design | Need help? Send a PM
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-02-2008, 01:38 AM
shiyam198 shiyam198 is offline
Newbie
 
Join Date: Sep 2008
Posts: 11
Rep Power: 0
shiyam198 is on a distinguished road
Default Re: Column count doesn't match value count at row 1

That is exactly I have in my code. I have attached it in my first original post. Do you find any thing wrong in that ?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 09-02-2008, 01:12 PM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 20
Posts: 3,433
Last Blog:
Google Web Toolkit
Rep Power: 20
John has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond repute
Send a message via AIM to John Send a message via MSN to John
Default Re: Column count doesn't match value count at row 1

Quote:
Originally Posted by shiyam198 View Post
That is exactly I have in my code. I have attached it in my first original post. Do you find any thing wrong in that ?
PHP Code:
('$_POST[fname]'),('$_POST[lname]'
is a little different than
PHP Code:
('$_POST[fname]''$_POST[lname]', ...) 
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | My Blog
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 09-02-2008, 06:54 PM
orjan's Avatar   
orjan orjan is offline
Programming Professional
 
Join Date: Sep 2007
Location: Sunne, Värmland, Sweden
Age: 33
Posts: 328
Last Blog:
Procedural Programming...
Rep Power: 9
orjan has a spectacular aura aboutorjan has a spectacular aura aboutorjan has a spectacular aura about
Default Re: Column count doesn't match value count at row 1

I counted your named columns and got those to 23, but then your values, I were counting to 24, so there are one value too much there...
and, you shall not have parenthesis around each value, as John mentions above.

and as you're entering all columns if i'm right, you don't have to specify them at all

table with three columns can be inserted like this:

Code:
insert into mytable values (1,2,3);
if you want to enter more than one row at a time, you can write

Code:
insert into mytable values (1,2,3), (4,5,6), (7,8,9);
for inserting three rows at once.

btw, your code seems a bit unsecure as you drop your $_POST values directly into the database, as there is easily sql injections possible there.
I know that someone here (John?) made an excellent tutorial on sql injections.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 09-02-2008, 09:28 PM
shiyam198 shiyam198 is offline
Newbie
 
Join Date: Sep 2008
Posts: 11
Rep Power: 0
shiyam198 is on a distinguished road
Default Re: Column count doesn't match value count at row 1

Thanks a lot for your help guys. I am blind for parenthesis I guess.
I will read upon SQL injection as well.

Thanks again every one!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 09-02-2008, 10:16 PM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 20
Posts: 3,433
Last Blog:
Google Web Toolkit
Rep Power: 20
John has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond repute
Send a message via AIM to John Send a message via MSN to John
Default Re: Column count doesn't match value count at row 1

Quote:
Originally Posted by orjan View Post
btw, your code seems a bit unsecure as you drop your $_POST values directly into the database, as there is easily sql injections possible there.
I know that someone here (John?) made an excellent tutorial on sql injections.
I'm surprised I didn't mention that. Here is my explanation of SQL injections.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | My Blog
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 09-07-2008, 03:13 PM
Xav's Avatar   
Xav Xav is offline
Code Warrior
 
Join Date: Mar 2008
Location: On God's Planet
Posts: 9,583
Last Blog:
Web slideshow in JavaS...
Rep Power: 76
Xav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud of
Send a message via MSN to Xav
Default Re: Column count doesn't match value count at row 1

Hey, nice tutorial!
__________________


Mr. Xav | Website | Forums | Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using ODBC to determine column uniqueness & check constraints Tronman Database & Database Programming 1 05-21-2008 12:01 PM
Java:Tutorial - Tic-Tac-Toe John Java Tutorials 25 02-27-2008 07:41 PM
Getting Row Count Lop Managed C++ 2 01-10-2007 09:17 AM


All times are GMT -5. The time now is 06:12 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 97%

Ads