How to retrieve images from MySQL database and display in an html tag

后端 未结 5 1305
春和景丽
春和景丽 2020-11-22 02:34

I created a MySQL database with a table using phpmyadmin. I created this table with a BLOB column to hold a jpeg file.

I have issues with regards to the php variabl

5条回答
  •  自闭症患者
    2020-11-22 03:37

    I have added slashes before inserting into database so on the time of fetching i removed slashes again stripslashes() and it works for me. I am sharing the code which works for me.

    How i inserted into mysql db (blob type)

    $db = mysqli_connect("localhost","root","","dName"); 
    $image = addslashes(file_get_contents($_FILES['images']['tmp_name']));
    $query = "INSERT INTO student_img (id,image) VALUES('','$image')";  
    $query = mysqli_query($db, $query);
    

    Now to access the image

    $sqlQuery = "SELECT * FROM student_img WHERE id = $stid";
    $rs = $db->query($sqlQuery);
    $result=mysqli_fetch_array($rs);
    echo '';
    

    Hope it will help someone

    Thanks.

提交回复
热议问题