PHP〜列数与第1行的值数不匹配 [英] PHP ~ Column count doesn't match value count at row 1

查看:44
本文介绍了PHP〜列数与第1行的值数不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建注册,我只使用纯PHP而不是JavaScript来将表单发送到MySQL数据库,因此一切正常,没有语法错误或其他任何内容,但我填写了所有信息,然后单击注册" ",并返回一条消息列数与第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'.

我只有14岁,所以这让我很困惑,有人可以解决吗?

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

这是我的INSERT INTO代码:

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());

推荐答案

您正试图在8列中插入7个值-您没有插入性别.

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

正确的代码是:

$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.

这篇关于PHP〜列数与第1行的值数不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆