Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
724 views
in Technique[技术] by (71.8m points)

mysql - PHP ~ Column count doesn't match value count at row 1

I'm creating a registration and I'm using just straight PHP not JavaScript to send my form to the MySQL database, so everything is working fine, no syntax error or anything but I fill out all my information and click 'Register' and it returns a message saying 'Column count doesn't match value count at row 1'.

I'm only 14 so this is pretty confusing for me does anyone have a solution?

This is my INSERT INTO code:

 $sql = mysql_query("INSERT INTO users(firstname, lastname, email, password, day, month, year, gender) 
 VALUES('$firstname','$lastname','$email','$db_password','$day','$month','$year')")  
 or die (mysql_error());
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You are trying to insert 7 values into 8 columns - you are missing the insertion of gender.

The correct code would be:

$sql = mysql_query("INSERT INTO users(firstname, lastname, email, password, day, month, year, gender) 
VALUES('$firstname','$lastname','$email','$db_password','$day','$month','$year', '$gender')")  
or die (mysql_error());

By the way, if you are not already doing it, I highly recommend escaping the strings first, before passing them to the query like so:

$firstname=mysql_real_escape_string($firstname)

You should do this with all variables above. Here you can find more about the escape function.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...