Forum Moderators: open

Message Too Old, No Replies

MySql Column count does not match

I am a complete newb to mysql and php

         

MrWhippy

8:36 pm on Jan 15, 2008 (gmt 0)

10+ Year Member



Hi All,

i am completley new to php and mysql and am having varied amounts of success, the problem i have at the moment is that inserting to my table, i get "Column count doesn't match value count at row 1"

i have googled this finding that all the sites say i dont have enough fields in my statement, when reading it myself it seems to have enough am i just missing the point here i have included the statement that i believe is causing me the problem below.

all help greatfully recieved.

$query = "INSERT INTO user (user_id, user_name, first_name, surname, password, email, mobile, auth_lvl)
VALUES('$null', '$UserName', '$FirstName', '$SurName', '$Password', '$EmailAddr', '$ContactNum' '$authlevel')" ;
mysql_query($query)
or die(mysql_error());

ZydoSEO

5:36 am on Jan 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm guessing that since you seem to be passing in a value of '$null' for user_id that perhaps user_id is an auto-increment field where the database generates a sequential number on each insert. If this is the case then you do not need to supply the user_id field name in the list of fields, nor do you have to provide a '$null' in the VALUES clause...

So IF user_id is an auto-increment field your SQL statement should probably look like:

INSERT INTO user (user_name, first_name, surname, password, email, mobile, auth_lvl)
VALUES('$UserName', '$FirstName', '$SurName', '$Password', '$EmailAddr', '$ContactNum' '$authlevel')

MrWhippy

10:46 pm on Jan 16, 2008 (gmt 0)

10+ Year Member



Ah thanks,

think i put that in there as i found somewhere that you need to have the auto increment in the value bit and pass it through, i will give it a try.

MrWhippy

9:13 pm on Jan 21, 2008 (gmt 0)

10+ Year Member



hi all,

tried what was suggested above, oh and sorry in the delay been very busy, but just found the problem i was having there was a comma missing in the variables inbetween the last two fields.

so sorry to trouble anyone