查询中的错误在哪里?
if(empty($errors) == true){
move_uploaded_file($file_tmp, "images/".$file_name);
$sql = "UPDATE gallery SET i1 = 'images/'".$file_name."' WHERE v_id = 1";
$res = mysqli_query($con, $sql) or die(mysqli_error($con));
echo "Success";}
上传任何文件后我收到此错误。
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'Jellyfish.jpg' WHERE v_id = 1' at line 1
答案 0 :(得分:1)
void data(char [] TxBits)
答案 1 :(得分:1)
您可以在查询中使用$file_name
变量:
$sql = "UPDATE gallery SET i1 = 'images/{$file_name}' WHERE v_id = 1";
$file_name
是一个字符串,因此您可以在{$file_name}
我的测试示例:
$file_name = "test.jpg";
echo $sql = "UPDATE gallery SET i1 = 'images/{$file_name}' WHERE v_id = 1";
<强>结果:强>
UPDATE gallery SET i1 = 'images/test.jpg' WHERE v_id = 1
旁注:
这只是建议请为您的列和表使用正确的名称没有人能理解i1
的含义我认为image_1
答案 2 :(得分:0)
你已经弄乱了i1
值周围的单引号,试试这个:
if(empty($errors) == true){
move_uploaded_file($file_tmp, "images/".$file_name);
$sql = "UPDATE gallery SET i1 = 'images/".$file_name."' WHERE v_id = 1";
$res = mysqli_query($con, $sql) or die(mysqli_error($con));
echo "Success";}