gpt4 book ai didi

php - 无效查询 : You have an error in your SQL syntax

转载 作者:行者123 更新时间:2023-12-01 00:20:13 24 4
gpt4 key购买 nike

<?php
mysql_connect("mysql6.000webhost.com","a6124751_murali1","***");
$db= mysql_select_db("a6124751_signup");
$topic=$_GET["Topic"];
$question=$_GET["Question"];
$company =$_GET["Company"];
$query = "INSERT INTO questions (topic, question, company) VALUES ($topic, $question, $company)";
$sql1=mysql_query($query);
if (!$sql1) {
die('Invalid query: ' . mysql_error());
}
?>

这是我在服务器中的 php 代码,其中有一个名为“questions”的表,我试图从前端使用表单从 GET 方法获得的输入中插入数据,我可以弄清楚数据是正确地来 self 使用 echo 检查过的客户端。我收到一个错误

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 'name, type your question here, company)' at line 1

不知道查询中的错误是什么。任何人尽快找到它。谢谢

最佳答案

你需要引用你的值(value)观

('$topic', '$question', '$company')

因为那些是字符串。

此外,出于某些原因,您应该转义数据。不让 MySQL 提示某些字符,如连字符等,并防止 SQL 注入(inject)。

使用准备好的语句:

引用资料:


编辑:

以使用您当前的 MySQL API 为例:

$topic    = mysql_real_escape_string($_GET['topic']);
$question = mysql_real_escape_string($_GET['question']);
$company = mysql_real_escape_string($_GET['company']);

我不知道你的输入叫什么,所以这只是一个例子。

您提到过使用 $_GET 进行调试,但使用的是 POST 方法。

  • 将上面所有的$_GET改为$_POST

关于php - 无效查询 : You have an error in your SQL syntax,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31554319/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com