如何将数据从数据库显示到不同的页面

时间:2018-04-30 17:38:45

标签: php database

所以我有这个代码将图像存储到数据库中并检索它们。这些图片当前显示在您提交照片的表格下的profiletest.php页面上。相反,我希望这些图像显示在exploretest.php页面上。我该怎么做呢?

profiletest.php

<?php
   if (isset($_POST['submit']))
   {
       if (getimagesize($_FILES['image']['tmp_name'])== FALSE)
       {
           echo "Please select an image.";
       }
       else
       {
           $name= addslashes($_FILES['image']['name']);
           $image= base64_encode(file_get_contents(addslashes($_FILES['image']['tmp_name'])));
           saveimage($name,$image);
       }
   }

   function saveimage($name, $image)
   {
       $conn = mysqli_connect("localhost","root","","loginsystem"); 

       $sql="insert into testimage(name,image) values('$name', '$image')";
       $query=mysqli_query($conn,$sql);
       if ($query)
       {
           echo "<br/>Image Uploaded.";
       }
       else
       {
           echo "<br/>Image not uploaded";
       }
   }
    display();

     function display(){
       $conn = mysqli_connect("localhost","root","","loginsystem");
        $sql="select * from testimage";
         $query=mysqli_query($conn, $sql);
         $num=mysqli_num_rows($query);
         for ($i=0; $i < $num; $i++) {
             $result=mysqli_fetch_array($query);
             $img=$result['image'];
             echo '<img  class="exploreimg" src="data:image;base64, '.$img.'" style="max-height:300px;max-width:300px; margin-left:50px; margin-right:50px; padding-bottom:20px; padding-top:30px;">';


         }
     }

?>  

0 个答案:

没有答案