SQL UPDATE错误图像上载

时间:2016-02-17 07:44:55

标签: php mysql sql

查询中的错误在哪里?

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

3 个答案:

答案 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";}