gpt4 book ai didi

javascript - mysql 在某些表单字段上插入失败

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

当我尝试插入 mysql 数据库时出现以下错误。

MYSQL Error: 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 'Condition, Status) VALUES ( '20140715_173221.jpg','rt', 'Vessel', 'hf',' ','New'' at line 1

我可以在没有字段 Condition 和 Status 的情况下正常插入。这是表单/javascript。

<script type="text/javascript">
$(document).ready(function(){
$('#upload select[name="Type"]').change(function(){
if($('#upload select[name="Type"] option:selected').val() == 'Shroud' || $('#upload select[name="Type"] option:selected').val() == 'Vessel' ){
$('#Status').show();
}else{
$('#Status').hide();
}
});
});

$(document).ready(function(){
$('#upload select[name="Type"]').change(function(){
if($('#upload select[name="Type"] option:selected').val() == 'Collector' ||
$('#upload select[name="Type"] option:selected').val() == 'M150' ||
$('#upload select[name="Type"] option:selected').val() == 'TC' ){
$('#Condition').show();
}else{
$('#Condition').hide();
}
});
});

</script>
<form id="upload" name="upload" enctype="multipart/form-data" action="ImageUpload.php" method="POST">

<label for="Type">Type:</label>
<select id="Type" name="Type">
<option value="">Select a Type...</option>
<option value="Shroud">Shroud</option>
<option value="Vessel">Vessel</option>
<option value="Collector">Collector</option>
<option value="M150">M150</option>
<option value="TC">TC</option>
<option value="VanesHOBIF">Vanes/HOB/IF</option>
</select><br><br>


Title: <input type="text" name="UserTitle"><br>

<div id="Status" style="display:none">Status:
<input type="text" name="Status" value="">
<br>
</div>

<div id="Condition" style="display:none">
<label for="Condition">Condition:</label>
<select name="Condition">
<option value=" "></option>
<option value="New">New</option>
<option value="Cleaned">Cleaned</option>
<option value="Drained">Drained</option>
<option value="NA">NA</option>
</select><br><br>
</div>


<label for="Desciption">Description:</label><br>
<textarea type="text" name = "Description" cols="40" rows= "4"></textarea><br>
File: <input type="file" name="file" id="file"><br>
<input type="submit" name="submit"value="Submit">
</form>

和我的 PHP Post 文件

$title=$_POST['Title'];
$usertitle=$_POST['UserTitle'];
$type=$_POST['Type'];
$Description=$_POST['Description'];
$files=($_FILES['file']['name']);
$Condition=$_POST['Condition'];
$Status= $_POST['Status'];



$sql="INSERT INTO ImageTable (Title,UserTitle,Type,Description,Condition, Status) VALUES ( '$files','$usertitle', '$type', '$Description','$Condition','$Status')";

if (!mysqli_query($con,$sql))
{
die('MYSQL Error: ' . mysqli_error($con));
}

如果我回显 $Condition 和 $Status,我会看到在表单中选择的值。不确定插入语句出了什么问题。提前致谢

最佳答案

Condition 是 MySQL 保留字。

http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html

如果您想继续将其用作列名,请在其周围加上刻度线:

`Condition`

(Title,UserTitle,Type,Description,`Condition`, Status)

关于javascript - mysql 在某些表单字段上插入失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24896295/

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