简体   繁体   中英

How to get the an image from mysql database in php

I have this code which should search for pictured in mysql database, am not sure if it is working,

I want to get the images the user search for and post them in the html, can i do this?

Here is my code

<?php 
    require('connect.php');
      if(isset($_POST['submit'])){ 
      if(isset($_GET['go'])){ 
      if(preg_match("/^[  a-zA-Z]+/", $_POST['name'])){ 
      $name=$_POST['name']; 
      //connect  to the database 
      //-query  the database table 
      $sql="SELECT * FROM cards WHERE name LIKE '%$searchQuery'"; 
      //-run  the query against the mysql query function 
      $result=mysql_query($sql); 
      //-create  while loop and loop through result set 
      while($row=mysql_fetch_array($result)){ 
              $name = $row['name'];
                $id = $row['id'];
      } 
      } 
      else{ 
      echo  "<p>Please enter a search query</p>"; 
      } 
      } 
      } 
    ?> 

To display the image [Where you have stored the image's path in db]

You shall just echo the coloumn with the image tag

echo "<img src =".$row['name'].">"; 

Note :

You should point the image the path where the image is stored in the files

Some thing like

echo "<img src ='assets/images/".$row['name']."'>"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM