Displaying broken image format from database using php,ajax;

I am trying to fetch data from my database that is using php ajax and javascript…
unfortunately i am not able to get image displayed in my browser. It shows up . it shows a broken image icon or sometimes a flood of binary data. I have stored the image column as simple BLOB type.

Here is my code->

<?php
class testdb
{
	public $con;
	private $host = "localhost";
	private $username = 'root';
	private $password = '';
	private $database = 'testdb';

	function __construct()
	{
	 $this->database_connect();
	}

	public function database_connect()
	{
	 $this->con = mysqli_connect($this->host,$this->username,$this->password,$this->database);
	}

	public function execute_query($query)
	{
	   return mysqli_query($this->con, $query);
	}
     public function get_data_in_table($query)
     {
       $output ='';
       $result = $this->execute_query($query);
       $output .= '
         <table class="table table-bordered table-striped">
         <tr>
             <th width="10%"> Image </th>
             <th width="10%"> Hname </th>
             <th width="30"> Hdes </th>
             <th width="20"> Hben </th>
             <th width="10%"> Pcure </th>
             <th width="10%"> Scure </th>
             <th width="10%"> cost </th>
         </tr>

       ';
       while($row = mysqli_fetch_object($result))
       {
          $output .= '

           <tr>
           <td><img src="/Applications/XAMPP/xamppfiles/htdocs/p5/upload'.$row->image.'" class="img-thumbnail" width="50" height="35"/></td>
           <td>'.$row->Hname.'</td>
           <td>'.$row->Hdesc.'</td>
           <td>'.$row->Hben.'</td>
           <td>'.$row->Pcure.'</td>
           <td>'.$row->Scure.'</td>
           <td>'.$row->cost.'</td>
           <td> <button type="button" name="update" id="'.$row->hid.'" class="btn btn-sucsess btn-xs update ">Update </button> </td>
           <td> <button type="button" name="delete" id="'.$row->hid.'" class="btn btn-sucsess btn-xs delete ">Delete </button> </td>           


           </tr>



          ';
       } $output .= '</table>';
       return $output;
       }
}
?>

well this is my Database code:

CREATE DATABASE `testdb`;
USE `testdb`;
CREATE TABLE IF NOT EXISTS `herbs'` (
  `hid` int(8) NOT NULL AUTO_INCREMENT,
  `Hname` varchar(30) NOT NULL,
  `image` BLOB NOT NULL,
  `Hdesc` varchar(40) NOT NULL,
  `Hben` varchar(40) NOT NULL,
`Pcure` varchar(40) NOT NULL,
`Scure` varchar(40) NOT NULL,
`cost` int(100) NOT NULL, 
PRIMARY KEY (`id`),
  UNIQUE KEY `email` (`email`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

i use safari browser and Xampp 5.6.30-0 in Mac OS

thanks @cpradio… ur previous work helped me get my image work as well… it was the problem of the upload directory which was causing this issue… anyways… thanks :slight_smile:

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.