如何从数据库php捕获和显示图像

时间:2019-07-17 08:22:43

标签: php html

我想从phpmyadmin数据库中检索图像。当前,图片的链接保存在数据库中。但是当我检索它时,什么也没显示。

//form2.php (uploading of image)
<div>
<label>Attachment:</label><input type='file' name='img'><br>
</div>

//insert2.php
    <?php

    $con= mysqli_connect('127.0.0.1','root','');

    if(!$con)
    {
        echo 'Not Connected To Server';
    }

    if(!mysqli_select_db($con,'satsform1'))
    {
        echo 'Database Not Selected';
    }

    $name = $_GET['name'];
    $staffno = $_GET['staffno'];
    $date = $_GET['date'];
    $time = $_GET['time'];
    $email = $_GET['email'];
    $mobno = $_GET['mobno'];
    $roles = $_GET['roles'];
    $location = $_GET['location'];
    $flightno = $_GET['flightno'];
    $flightdate = $_GET['flightdate'];
    $seatno = $_GET['seatno'];
    $class = $_GET['class'];
    $description = $_GET['description'];
    $image = $_GET['img'];
    $remarks = $_GET['remarks'];






    $sql = "INSERT INTO handover (name,staffno,date,time,email,mobno,roles,location,flightno,flightdate,seatno,class,description,image,remarks,status) 
    VALUES ('$name','$staffno','$date','$time','$email','$mobno','$roles','$location','$flightno','$flightdate','$seatno','$class','$description','$image','$remarks','Pending')";

    if(!mysqli_query($con,$sql))
    {
        echo 'Not Submitted';
    }
    else
    {
        echo 'Submitted';
    }


    header("refresh:2; url=selection.php")

?>


      <?php
//fetch3.php
$connect = mysqli_connect('127.0.0.1','root','', 'satsform1');
$output = '';
if(isset($_POST["query"]))
{
 $search = mysqli_real_escape_string($connect, $_POST["query"]);
 $query = "
  SELECT * FROM handover 
  WHERE name LIKE '%".$search."%'
  OR staffno LIKE '%".$search."%' 
  OR date LIKE '%".$search."%'
  OR email LIKE '%".$search."%'
  OR mobno LIKE '%".$search."%'
  OR roles LIKE '%".$search."%'
  OR location LIKE '%".$search."%'
  OR flightno LIKE '%".$search."%'
  OR flightdate LIKE '%".$search."%'
  OR seatno LIKE '%".$search."%'
  OR class LIKE '%".$search."%'
 ";
}
else
{
 $query = "
  SELECT * FROM handover ORDER BY ID
 ";
}
$result = mysqli_query($connect, $query);
if(mysqli_num_rows($result) > 0)
{
 $output .= '
  <div class="table-responsive">
   <table class="table table bordered">
    <tr>
     <th>ID</th>
     <th>Staff Name</th>
     <th>Staff Number</th>
     <th>Date</th>
     <th>Time</th>
     <th>Email</th>
     <th>Mobile Number</th>
     <th>Roles</th>
     <th>Location</th>
     <th>Flight Number</th>
     <th>Flight Date</th>
     <th>Seat Number</th>
     <th>Class of Travel</th>
     <th>Image</th>
     <th> Status </th>
    </tr>
 ';
 while($row = mysqli_fetch_array($result))
 {
  $output .= '
   <tr>
    <td>'.$row["ID"].'</td>
    <td>'.$row["name"].'</td>
    <td>'.$row["staffno"].'</td>
    <td>'.$row["date"].'</td>
    <td>'.$row["time"].'</td>
    <td>'.$row["email"].'</td>
    <td>'.$row["mobno"].'</td>
    <td>'.$row["roles"].'</td>
    <td>'.$row["location"].'</td>
    <td>'.$row["flightno"].'</td>
    <td>'.$row["flightdate"].'</td>
    <td>'.$row["seatno"].'</td>
    <td>'.$row["class"].'</td>
    <td><img src="'.$row["img"].'"></td> 
    <td>'.$row["status"].'</td>

    <td> <form action="edit3.php" method="GET">
     <input type="hidden" name="update_id" value="'.$row["ID"].'">
            <button type="submit">update </button>

        </form>
    </td>

   </tr> 
  ';
 }
 echo $output;
}
else
{
 echo 'Data Not Found';
}

?>

我希望将显示特定行的图片并显示该图片。因此,当我使用实时搜索引擎时,图片将根据其行显示在图片列下方。

1 个答案:

答案 0 :(得分:0)

请更改此:

<td><img src="'.$row["img"].'"</td>

对此:

<td><img src="'.$row["img"].'"></td>

希望获得帮助。