我不断收到此错误:
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.
我知道“组”字段有问题,因为如果删除它,我的表将得到更新而不会出现任何问题.
这是我的表单代码:
<form enctype="multipart/form-data" action="products_import_confirmation.PHP" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="99999999" />
<center><table><br><br>
<td>Prekės pavadinimas:
<td><input type="text" name="name_p" value="<?PHP echo $name_p;?>">
<span class="error">* <?PHP echo $name_pErr;?></span></td>
<tr>
<td>Gamintojas:<td><input type="text" name="brand" value="<?PHP echo $brand;?>">
<span class="error">* <?PHP echo $brandErr;?></span></td>
<tr>
<td>Specifikacijos:<td><textarea style="resize:none" name="specs" rows="5" cols="60"><?PHP echo $specs;?></textarea>
<span class="error">* <?PHP echo $specsErr;?></span></td>
<tr>
<td>Aprašymas:<td><textarea style="resize:none" name="about" rows="5" cols="60"><?PHP echo $about;?></textarea>
<tr>
<td>Kategorija:<td><select name="group" value="<?PHP echo $group;?>">
<option value="">Pasirinkite kategoriją</option>
<option disabled>------------------</option>
<option value="Telefonai">Telefonai</option>
<option value="Planšetės">Planšetės</option>
<option value="Kompiuteriai">Kompiuteriai</option>
</select>
<span class="error">* <?PHP echo $groupErr;?></span></td>
<td><div><input name="image" accept="image/jpeg" type="file" /></div></td>
<tr>
</center></table>
<td><div><input type="submit" value="Submit" /></div></td>
</form>
<?PHP
require("/includes/connection_to_db.PHP");
MysqL_query("SET NAMES 'utf8'");
session_start();
echo "<Meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>";
if(isset($_GET['logout']) && $_GET['logout'] == "true"){
unset($_SESSION['user_id']);
header("Location: index.PHP");
}
if (isset($_FILES['image']) && $_FILES['image']['size'] > 0)
{
// Temporary file name_p stored on the server
$tmpname_p = $_FILES['image']['tmp_name'];
// Read the file
$fp = fopen($tmpname_p, 'r');
$image = fread($fp, filesize($tmpname_p));
$image = addslashes($image);
fclose($fp);
date_default_timezone_set('Europe/Vilnius');
$V_ID = MysqL_real_escape_string($_SESSION['user_id']);
$name_p = MysqL_real_escape_string($_POST['name_p']);
$group = MysqL_real_escape_string($_POST['group']);
$brand = MysqL_real_escape_string($_POST['brand']);
$specs = MysqL_real_escape_string($_POST['specs']);
$about = MysqL_real_escape_string($_POST['about']);
$date = date('Y-m-d H:i:s');
$query = "INSERT INTO prekės (V_ID, name, group, brand, specs, about, image, date)
VALUES ($V_ID, '$name_p', $group, '$brand', '$specs', '$about', '$image', '$date')";
if(MysqL_query($query))
{
echo "Prekė ".$name." sėkmingai įkelta <br>";
echo "<a href=\"../main.PHP\">Grįžti</a>";
}
else
{
echo "Įvyko klaida: ".MysqL_error()."<br>";
echo "<a href=\"../products_import.PHP\">Grįžti</a>";
echo $date;
echo $name_p;
echo $brand;
echo $specs;
echo $about;
echo $group;
}
}
else
{
echo "Neužpildyti visi reikalaujami duomenys.";
}
MysqL_close();
?>
如您所见,我做了一些回显,以检查是否获得了数据,并且一切正常. “分组”数据只会使事情变糟.有任何想法吗?
解决方法:
您需要对保留字使用backtics作为
`group`
在这里检查他们的名单
https://dev.mysql.com/doc/refman/5.5/en/reserved-words.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。