图像未插入数据库

images is not inserting into database

提问人:FSO 提问时间:3/21/2021 更新时间:3/21/2021 访问量:127

问:

我在PHP中创建了一个图像上传页面。图像存储在根文件夹中,但没有插入数据库,我不知道我做错了什么................

这是我的代码

[html]

form action="" method="post" enctype="multipart/form-data" >

<input type="file" name="file">
<input type="submit" value="upload" name='submit'>
</form>

PHP的

$con=........

    if(isset($_POST['submit'])){

    $file=$_FILES['file'];

   $filename= $_FILES['file']['name'];
   $size=$_FILES['file']['size'];
   $temp=$_FILES['file']['tmp_name'];
   $error=$_FILES['file']['error'];

   $ext=explode('.', $filename);
   $actual=strtolower(end($ext));

   $allowed=array('jpg','png','jpeg');

   if (in_array($actual,$allowed)) {
       if ($error ===0) {
           if ($size <5000000) {
               $desti= 'uploads/'.$filename;
               move_uploaded_file($temp,$desti);
           }else{
            echo"limit is 50 mb";
           }
       }else{
        echo"network error";
       }
   }else{
       echo"wrong file type";
   }

   $res=mysqli_query($con, "insert into images('image') values('$desti')");
PHP 镜像 mysqli 插入

评论

0赞 FSO 3/21/2021
数据库表:id 图像名称 des
0赞 biesior 3/21/2021
是否调试了值?储蓄的途径是什么?你有没有发现流程被破坏的地方?在查询 SQL 语句之前,先对 SQL 语句进行回显,并尝试在任何 SQL 客户端中运行,以检查它是否不包含任何错误。
0赞 FSO 3/21/2021
您的 SQL 语法有错误;查看与您的 MariaDB 服务器版本相对应的手册,了解在第 1 行的 ''image') values('$desti')' 附近使用的正确语法
0赞 Professor Abronsius 3/21/2021
列名不会用引号括起来 - 请改用反引号。另外 - 如果您使用 a 您就不会遇到这个问题prepared statement
0赞 biesior 3/21/2021
首先,只需回显您的插入语句,看看出了什么问题。尝试在SQL客户端中运行它并解决所有问题。

答:

0赞 Professor Abronsius 3/21/2021 #1

假设上面显示的代码是实际代码,并且您的 sql 在列名周围有单引号,然后将 sql 从

$res=mysqli_query($con, "insert into images('image') values('$desti')");

$sql='insert into `images` (`image`) values (?)';
$stmt=$con->prepare($sql);
$stmt->bind_param('s',$desti);
$stmt->execute();