以下代码用于更新用户图像代码显示执行,但数据库中没有更改

nxowjjhe  于 2021-06-23  发布在  Mysql
关注(0)|答案(1)|浏览(222)
<form action="?action7" method="POST">
    <label for="fname">
        Update image
    </label>
    <input type="file" name="image">
    <input type="submit" name="submit" value="Submit">
    <?php
      if(isset($_GET['action7'])=='rdt')
      { 
         $image= addslashes($_FILES['image']['tmp_name']);
         $image= file_get_contents($image);
         $image= base64_encode($image);
         saveimage($image);
      }
      function saveimage($image)
      {
         $con=mysqli_connect("localhost","root","","mydb");
         mysqli_select_db($con,"photos");
         $qry="update images102 set image='$image' where email='$picmail'";
         $result=mysqli_query($con,$qry);
         if($result)
         {
             echo "image uploaded.";
         }
         else
         { 
             echo "image not uploaded";
         }
      }
    ?>
</form>

请注意: $picmail 是在此代码函数外部声明的全局变量。执行显示消息 "Image uploaded" . 但是,数据库显示旧图像中没有任何更改

gpnt7bae

gpnt7bae1#

你应该加上 enctype="multipart/form-data" 在窗体元素中 <form action="?action7" method="post" enctype="multipart/form-data">

相关问题