Jump to content

How to display image from mysql BLOB data type using PHP


maideen

Recommended Posts

Hi 

I am new. I am using Bootstrap css.

I have an issue to display image with data type BLOB, Really I don't know how to do this. 

Pls advise me how to do this.

Thanks

maideen

 

My php insert Code

<?php
require_once '../inc/config.php';

if(isset($_POST['add']))
{
    if($_SERVER["REQUEST_METHOD"] == "POST")
    {
      
      $sid =$_POST['sid'];
      $sname =$_POST['sname'];
      $nric=$_POST['nric'];
      $gender=$_POST['gender'];
      $dob=$_POST['dob'];
      $courseid=$_POST['courseid'];
      $pname=$_POST['pname'];
      $emailid=$_POST['emailid'];
      $hpno=$_POST['hpno'];
      $homeno=$_POST['homeno'];
      $offno=$_POST['offno'];
      $emergencyno=$_POST['emergencyno'];
      $address=$_POST['address'];
      $city=$_POST['city'];
      $state=$_POST['state'];
      $country=$_POST['country'];
      $hname=$_POST['hname'];
      $alergies=$_POST['alergies'];
      $milkpowder=$_POST['milkpowder'];
      $specialfoods=$_POST['specialfoods'];
      $specactivy1=$_POST['specactivy1'];
      $specactivy2=$_POST['specactivy2'];
      $specactivy3=$_POST['specactivy3'];
      $specactivy4=$_POST['specactivy4'];
      $simage=$_POST['simage'];
      $createdby =$_POST['username'];
      $time = strftime("%X");
      $date = strftime("%B %d,%Y");
      //$createdon= $date;
      $createdon = date("Y-m-d H:i:s");
      $bool = true;
      $sql="insert into tbl_student_master(sid,sname,nric,gender,dob,courseid,pname,emailid,hpno,homeno,offno,emergencyno,address,city,state,country,hname,alergies,milkpowder,
            specialfoods,specactivy1,specactivy2,specactivy3,specactivy4,simage,createdby,createdon) 
            values ('$sid','$sname','$nric','$gender','$dob','$courseid','$pname','$emailid','$hpno','$homeno','$offno','$emergencyno','$address','$city','$state','$country',
                    '$hname','$alergies','$milkpowder','$specialfoods','$specactivy1','$specactivy2','$specactivy3','$specactivy4','$simage','$createdby','$createdon')";
      $stmt=$pdo->prepare($sql);
      $stmt->execute();
      $pdo = null;
      print '<script>alert("Saved");</script>';
      header("location:../student/student_add.php");  
    }
}  

Insert HTML

                        <div class="col-md-9">
                            <div class="fileinput fileinput-new" data-provides="fileinput">
                                <div class="fileinput-new thumbnail" style="width: 200px; height: 150px;">
                                    <img src="http://www.placehold.it/200x150/EFEFEF/AAAAAA&text=no+image" alt="" /> </div>
                                <div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 200px; max-height: 150px;"> </div>
                                <div>
                                    <span class="btn default btn-file">
                                        <span class="fileinput-new"> Select image </span>
                                        <span class="fileinput-exists"> Change </span>
                                        <input type="file" name="simage"> </span>
                                    <a href="javascript:;" class="btn red fileinput-exists" data-dismiss="fileinput"> Remove </a>
                                </div>
                            </div>
                        </div>

 My display php code

<?php

if($_SERVER["REQUEST_METHOD"] == "GET")
    {
        $id=$_GET['id'];
        $sql ="Select * from tbl_student_master where id ='$id'";
        $stmt = $pdo->prepare($sql);
        $stmt->execute();
            while ($row = $stmt->fetch())
            {
              $id =$row['id'];
              $sid =$row['sid'];
              $sname =$row['sname'];
              $nric=$row['nric'];
              $gender=$row['gender'];
              $dob=$row['dob'];
              $courseid=$row['courseid'];
              $pname=$row['pname'];
              $emailid=$row['emailid'];
              $hpno=$row['hpno'];
              $homeno=$row['homeno'];
              $offno=$row['offno'];
              $emergencyno=$row['emergencyno'];
              $address=$row['address'];
              $city=$row['city'];
              $state=$row['state'];
              $country=$row['country'];
              $hname=$row['hname'];
              $alergies=$row['alergies'];
              $milkpowder=$row['milkpowder'];
              $specialfoods=$row['specialfoods'];
              $specactivy1=$row['specactivy1'];
              $specactivy2=$row['specactivy2'];
              $specactivy3=$row['specactivy3'];
              $specactivy4=$row['specactivy4'];
              $simage=$row['simage'];   
            }
    }
  
?>

My Display HTML

                        <div class="col-md-9">
                            <div class="fileinput fileinput-new" data-provides="fileinput">
                                <div class="fileinput-new thumbnail" style="width: 200px; height: 150px;">
                                    <img src="" alt=""  /> 
                                    <?php echo $simage; ?>
                                </div>
                                <div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 200px; max-height: 150px;"></div>
                                <div>
                                    <span class="btn default btn-file">
                                        <span class="fileinput-new"> Select image </span>
                                        <span class="fileinput-exists"> Change </span>
                                        <input type="file" name="simage"> </span>
                                    <a href="javascript:;" class="btn red fileinput-exists" data-dismiss="fileinput"> Remove </a>
                                </div>
                            </div>
                        </div>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.