字段列表中的未知列。PHP + mysql
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18368017/
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
Unknown Column in Field List. PHP + Mysql
提问by Giani Noyez
I'm trying to add values to a table in phpmyadmin and I get the error: Unknown column '...' in 'field list'.
我正在尝试向 phpmyadmin 中的表添加值,但出现错误:“字段列表”中的未知列“...”。
Here's my code:
这是我的代码:
<?php
//preparing the patch to copy the uploaded file
$target_path = "images/";
//adding the name of the file, finishing the path
$target_path = $target_path . basename( $_FILES['image']['name']);
//moving the file to the folder
if(move_uploaded_file($_FILES['image']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['image']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
//getting input from the form
$name = $_POST['game'];
$description = $_POST['beschrijving'];
//preparing the query to insert the values
$query = "INSERT INTO tblGames (name, description, image) VALUES ($name, $description,". $target_path .")";
//opening connection to db
$link = mysql_connect('localhost', 'root', '');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
//selecting a db
mysql_select_db("BouncingGiani", $link) or die(mysql_error());
//running the query
$result = mysql_query($query) or die (mysql_error());
//closing the connection
mysql_close($link);
?>
so when I enter fds as name in the form on the previous page I get : Unknown column 'fds' in 'field list'. This never happened to me before and I have no idea on what is going on.
因此,当我在上一页的表单中输入 fds 作为名称时,我得到:“字段列表”中的未知列“fds”。这以前从未发生在我身上,我不知道发生了什么。
回答by Class
I think this
我认为这
$query = "INSERT INTO tblGames (name, description, image) VALUES ($name, $description,". $target_path .")";
should be
应该
$query = "INSERT INTO tblGames (name, description, image) VALUES ('$name', '$description', '". $target_path ."')";
回答by dazed-and-confused
It looks like the values should be quoted in your $query
statement, i.e. $name
, $description
, and $target_path
.
它看起来像值应该在被引用$query
的语句,即$name
,$description
和$target_path
。
$query = "INSERT INTO tblGames (name, description, image)
VALUES ('$name', '$description', '" . $target_path . "')";
回答by Siavash Paidar
What is mysql syntax error here in this code:
这段代码中的 mysql 语法错误是什么:
mysql_query("INSERT INTO Company SET Company name='".$companyname.",'name='".$name.",' Phone='".$phone.",' Username='".$username.",'
Password='".$password."'")
OR
或者
die(mysql_error());