2017-05-17 165 views
0

我想上傳學生資料圖片到MySQL,然後我想檢索這些圖片。現在我可以成功將圖像上傳到MySQL數據庫,但是,當我嘗試檢索未正確檢索的圖像時。如果有人有想法,請告訴我。謝謝。
這裏是我的代碼如何檢索使用PHP和MySQL的圖像

<?php 
 
echo' <form name="student" method="post" action=""> '; 
 
echo' <div class="row">'; 
 
echo' <div class="col-md-4">'; 
 
echo '<label>Voter NIC no</label>'; 
 
echo'<input type="text" name="ty" class="form-control border-input" >'; 
 
echo' </div></div>'; 
 
echo' <div class="col-md-4"> 
 
<div class="form-group"> 
 
<button class="btn btn-info" type="submit" name="se"><span class="glyphicon glyphicon-search"></span></button> </div> </div> </div> </form>';   
 
              
 
             \t \t \t \t \t \t 
 
require'database.php'; 
 
$ty = isset($_POST['ty']) ? $_POST['ty'] : ''; \t \t \t \t \t 
 
if(isset($_POST['se'])) 
 
{ 
 
    $sql="SELECT `registr_no`, `frist_name`, `middle_name`, `last_name`,`NIC_number`,`voterPic_name`, `img_path` 
 
FROM `voter` 
 
    WHERE NIC_number='$ty'"; 
 
$q1=mysqli_query($con,$sql); 
 
echo'<form method="POST">'; 
 
echo"<table class='table table-striped'>"; 
 
echo"<thead> 
 
      <th>Registr no</th> 
 
      <th>First Name</th> 
 
      <th>Middle Name</th> 
 
      <th>Last Name</th> 
 
      <th>NIC No </th> 
 
\t  <th>Profile Pic</th> 
 
\t  <th>Action</th> 
 
\t \t \t 
 
       </thead> "; \t 
 
\t \t \t 
 
while($rows=mysqli_fetch_array($q1,MYSQL_ASSOC)) 
 
{ 
 
$id=$rows['voter_registr_no']; 
 
$fname=$rows['frist_name']; 
 
$mname=$rows['middle_name']; 
 
$lname=$rows['last_name']; 
 
$pic =$rows['img_path']; 
 
$nic=$rows['NIC_number']; 
 
    
 
    
 
echo"<tr><td>$id</td><td>$fname</td><td>$mname</td><td>$lname</td><td>$nic</td><td><img src='pictures/.$pic alt='' height='100' width='100''/> </td> 
 
<td><button type='submit' name='ok' class='btn btn-sm btn-default'><span class='glyphicon glyphicon-ok'></span></button></td></tr>"; 
 
echo"</table> 
 

 
</form>"; 
 

 
} 
 

 
} \t \t \t \t \t \t \t 
 

 
\t ?>

正如你可以看到這裏的Output

+0

你會得到什麼錯誤? – Exprator

+0

圖像未在輸出中檢索。看到這個鏈接。 Itz我的輸出https://i.stack.imgur.com/QT3U3.jpg – user5702902

+0

右鍵單擊並粘貼您在圖像的src中看到的網址 – Exprator

回答

0

請確保圖像的鏈接是正確的應該是類似的東西
您的域/圖片文件夾路徑/圖片路徑/圖像名稱與擴展

0

請確保您只在DB中存儲圖像名稱,而不是整個路徑。如果你已經在數據庫中存儲完整路徑,那麼你只需要提及。

<img src='.$pic. alt='' height='100' width='100''/> 

無需添加「圖片/」因爲你已經存儲在數據庫路徑。

相關問題