我正在网站上工作,现在无法访问myPhpAdmin,因此我尝试制作一个脚本来为搜索内容插入值。但是,当我访问链接website.com/search/create.php?l=link&d=description&t=title
时,出现错误。这个
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'link, description, title)' at line 1
这是我的脚本的样子。
$link = "https://website.com";
$description = "The homepage of the site";
$title = "Home";
// sql to create table
$sql = "INSERT INTO search (link, description, title) VALUES (".$link.", ".$description.", ".$title.")";
if (mysqli_query($conn, $sql)) {
echo "it's working";
} else {
echo "it's not working?" . mysqli_error($conn);
}
答案 0 :(得分:1)
替换
$sql = "INSERT INTO search (link, description, title) VALUES ('".$link."', '".$description."', '".$title."')";
而不是:
$sql = "INSERT INTO search (link, description, title) VALUES (".$link.", ".$description.", ".$title.")";
您正在尝试插入不包含'
的字符串答案 1 :(得分:0)
只需更改代码中的查询语法并进行检查即可...希望您的错误得到解决。
// sql to create table
$sql = "INSERT INTO search (link, description, title) VALUES ('$link', '$description', '$title')";
答案 2 :(得分:0)
似乎您在SQL查询中缺少单引号,请尝试以下操作:-
$sql = "INSERT INTO search (link, description, title) VALUES ('".$link.", '".$description."', '".$title."')";
答案 3 :(得分:0)
您将数据插入数据库表的代码是错误的(假设您已经执行了数据库连接查询($ conn)并在数据库上具有“搜索”表)。
$sql = "INSERT INTO search (link, description, title) VALUES ('$link', '$description', '$title')";
您不必在SQL查询中放入串联运算符(。),因为您无需串联PHP和标记文本。