gpt4 book ai didi

php - MySQL 在输入长文本时出现语法错误

转载 作者:行者123 更新时间:2023-11-29 08:50:32 26 4
gpt4 key购买 nike

我正在尝试使用 MySQL 构建 PHP 表单。问题是,如果我尝试在字段中添加一些长文本,每次都会收到错误。

错误

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.....at line 1

生成查询的 PHP 代码是这样的:

<?php

if ( $_GET['aktion'] == "speichern" )
{
$title = $_GET['title'];
$description = $_GET['description'];
$applepart = $_GET['applepart'];
$partnumber = $_GET['partnumber'];
$productcode = $_GET['productcode'];
$compatibility = $_GET['compatibility'];
$url_bild = $_GET['url_bild'];
$price = $_GET['price'];

$sql = "INSERT INTO adressbuch ";
$sql .= " SET ";
$sql .= " title = '$title', ";
$sql .= " description = '$description', ";
$sql .= " applepart = '$applepart', ";
$sql .= " partnumber = '$partnumber', ";
$sql .= " productcode = '$productcode', ";
$sql .= " compatibility = '$compatibility', ";
$sql .= " url_bild = '$url_bild', ";
$sql .= " price = '$price' ";

require_once ('konfiguration.php');
$db_erg = mysql_query($sql)
or die("Anfrage fehlgeschlagen: " . mysql_error());

echo '<h1>Adresse wurde speichert</h1>';
echo '<a href="auflistung.php">Auflistung anzeigen</a>';
exit;
}
?>

<form name="" action="" method="GET" enctype="text/html">
<p>Title:<br />
<input type="text" name="title" value="" size="60" />
</p>
<p>description:<br />
<input type="text" name="description" value="" size="60" />
</p>
<p>applepart:<br />
<input type="text" name="applepart" value="" size="60" />
</p>
<p>partnumber:<br />
<input type="text" name="partnumber" value="" size="60" />
</p>
<p>productcode:<br />
<input type="text" name="productcode" value="" size="60" />
</p>
<p>compatibility:<br />
<input type="text" name="compatibility" value="" size="60" />
</p>
<p>Bild:<br />
<input type="text" name="url_bild" value="" size="60" />
</p>
<p>price:<br />
<input type="text" name="price" value="" size="60" />
</p>

<input type="hidden" name="aktion" value="speichern" />

<input type="Submit" name="" value="speichern" />
</form>

感谢您的帮助

最佳答案

您的代码很容易受到 SQL 注入(inject)的影响,您的问题只是提示其原因。

我们始终使用的规则是:“永远不要信任来自用户代理的数据”(即将 $_GET 或 $_POST 中的任何内容视为潜在问题或更糟)。至少,我们应该始终使用 mysqli_real_escape_string 转义这些值。或者更强大的数据库框架。

关于php - MySQL 在输入长文本时出现语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11371397/

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