PHP、MySQL 错误:列数与第 1 行的值数不匹配
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5931900/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP, MySQL error: Column count doesn't match value count at row 1
提问by max_
I'm getting this error:
我收到此错误:
Column count doesn't match value count at row 1
Column count doesn't match value count at row 1
From the following code:
从以下代码:
$name = $_GET['name'];
$description = $_GET['description'];
$shortDescription = $_GET['shortDescription'];
$ingredients = $_GET['ingredients'];
$method = $_GET['method'];
//$image = $_GET['image'];
$username = $_GET['username'];
$length = $_GET['length'];
$dateAdded = uk_date();
$conn = mysql_connect('localhost', 'dbname', 'pass');
mysql_select_db('dbname');
$query = sprintf("INSERT INTO dbname (id, Name, Description, shortDescription, Ingredients, Method, Length, dateAdded, Username) VALUES ('', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",
mysql_real_escape_string($name),
mysql_real_escape_string($description),
mysql_real_escape_string($shortDescription),
mysql_real_escape_string($ingredients),
//mysql_real_escape_string($image),
mysql_real_escape_string($length),
mysql_real_escape_string($dateAdded),
mysql_real_escape_string($username));
$result = mysql_query($query) or die(mysql_error());
What does the error mean?
错误是什么意思?
回答by Ignacio Vazquez-Abrams
You have 9 fields listed, but only 8 values. Try adding the method.
您列出了 9 个字段,但只有 8 个值。尝试添加方法。
回答by Tharsan
The number of column parameters in your insert query is 9, but you've only provided 8 values.
插入查询中的列参数数为 9,但您只提供了 8 个值。
INSERT INTO dbname (id, Name, Description, shortDescription, Ingredients, Method, Length, dateAdded, Username) VALUES ('', '%s', '%s', '%s', '%s', '%s', '%s', '%s')
The query should omit the "id" parameter, because it is auto-generated (or should be anyway):
查询应该省略“id”参数,因为它是自动生成的(或者应该是):
INSERT INTO dbname (Name, Description, shortDescription, Ingredients, Method, Length, dateAdded, Username) VALUES ('', '%s', '%s', '%s', '%s', '%s', '%s', '%s')
Good luck!
祝你好运!
回答by MCForty
Your query has 8 or possibly even 9 variables, ie. Name, Description etc. But the values, these things ---> '', '%s', '%s', '%s', '%s', '%s', '%s', '%s')"
, only total 7, the number of variables have to be the same as the values.
您的查询有 8 个甚至 9 个变量,即。名称,描述等。 但是值,这些东西 ---> '', '%s', '%s', '%s', '%s', '%s', '%s', '%s')"
,总共只有 7 个,变量的数量必须与值相同。
I had the same problem but I figured it out. Hopefully it will also work for you.
我有同样的问题,但我想通了。希望它也适合你。