Page 1 of 1

Upload a blob from a mysql database using PHP

Posted: Thu Mar 24, 2011 3:47 am
by scottb
Can anyone help me at present I am storing images in blob format in a mysql database, I am trying to retrieve these images and display them along with other fields in the web page but am only getting text output back from the blob that looks like jargon. I will admit to being rusty in this area as its been almost 6 years since last did any html or PHP work so any help would be great

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- TemplateBeginEditable name="doctitle" -->
<title>Burning Curiosity Providers of stoves and fires</title>
<!-- TemplateEndEditable -->
<!-- TemplateBeginEditable name="head"-->
<!-- TemplateEndEditable -->
<link href="bitsconsultancy test.css" rel="stylesheet" type="text/css" />
<!--

[if IE]
<style type="text/css"> 
/* place css fixes for all versions of IE in this conditional comment */
.thrColElsHdr #sidebar1, .thrColElsHdr #sidebar2 { padding-top: 30px; }
.thrColElsHdr #mainContent { zoom: 1; padding-top: 15px; }
/* the above proprietary zoom property gives IE the hasLayout it needs to avoid several bugs */
</style>-->

<style type="text/css">
.style1 {
	font-size: 16px
}
.style2 {font-family: "Times New Roman", Times, serif}
.style3 {color: #0000CC}
body {
	margin-left: 10px;
	background-color: #FFFFFF;
	margin-right: 10px;
	padding-left: 10px;
	padding-right: 10px;
}
.style8 {
	font-family: Arial, Helvetica, sans-serif;
	color: #CCCCCC;
}
.style9 {
	color: #CCCCCC;
	font-family: Arial, Helvetica, sans-serif;
	font-weight: bold;
}
</style>
<style type="text/css">
.style1 {color: #FF0000}
.style2 {color: #FF0033}
.style3 {font-weight: bold}
.style5 {font-family: "Courier New", Courier, monospace,bold}
.style10 {
	color: #FFFFFF;
	font-weight: bold;}
.style11 {
	color: #0000FF;
	font-weight: bold;
}
.style12 {
font-size:14px
}
.style13 {color: #DC4D38}
</style>
<?php
$user="c9226823_scott";
$password="ncc1701d";
$database="c9226823_burning_curiosity";
$link=mysql_connect("localhost",$user,$password)or die(mysql_error());
mysql_select_db($database,$link) or die("Unable to select database");
$test = "select DISTINCT (manufacturer) FROM Product";
$result = mysql_query($test) or die("Couldnt' execute query.");
$num = mysql_numrows($result);
?>
<?
	$Stoveselect= $_POST['stoveselect'];
	echo $Stoveselect;
	$Stovefind = "SELECT * FROM Product where stove_type LIKE '%$stoveselect%'";
	$stoveresult= mysql_query($Stovefind) or die("Couldnt' execute query.");
	$stovenum = mysql_numrows($stoveresult);
?>
</head>
<body class="thrColElsHdr"> 
<div id="header">
<div class="style2" id="header">
    <h1 align="right" class="style1 style3"><a href="index.html"><img src="burning Curiosity Logo.jpg" width="240" height="65" align="left"/></a><span class="style5">Supply and Installation of Stoves and Fires </span></h1>
<h1 align="right" class="style1 style3"><span class="style5">Telephone: 01695 571684</span>  </h1>
<p>&nbsp;</p>
</div></div>
  <div id="menubar">
    <span class="style9"></span>
    <table width="100%" height="32" border="0" align="left" cellpadding="0" cellspacing="0" background = 		
    "menubar2.jpg">
      <tr><td width="4" height="17" background="menubar2.jpg"></td>
      <td width="183" class="Home"><div align="center" class="style9"><strong><a href="index.html">Home</a></strong></div></td> 
      <td width="186" height="18" class="contact"><div align="center" class="style9"><strong><a href="index.html">Contact Us</a></strong></div></td>
      <td width="115" class="Help"><div align="center" class="style9"><strong><a href="index.html">Help</a></strong></div></td>
      <td width="158" class="Showrooms"><div align="center" class="style9"><strong><a href="index.html">Show rooms</a></strong></div></td>
      <td width="205" class="installation"><div align="center"><strong><span class="style8"><a href="index.html">Installation</a></span></strong></div></td>      
  </table>
  <P>&nbsp;
  </P>
</div>
  <div id="sidebar1">
<form  method="post" action="search.php"  id="searchform">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td width="100%" background="sidemenubar.jpg"> <div align="center" class="style10">
        <div align="center">SEARCH</div>
      </div>
      <td> <div width ="100%"align="center">
        <input  type="text" name="search_query">
      </div></td>
    </tr>
  </table>
  <input type="image" src= "search button.jpg" align="middle"/>
  </form>
  <form  method="post" action="stoveselect.php"  id="stoveselect">
  <table width="80%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
  <td>&nbsp;</td>
  </tr>
    <tr>
      <td width="12%" background="sidemenubar2.jpg"> <div align="center" class="style10">
        <div align="center" class="style12">TYPE OF STOVE</div>
      </div></td>
      </tr>
    </table>
    <tr><div>
<td width="60%"><select name="stoveselect" size="1" value="<? stoveselect?>">
  <option value="" selected>Please Select</option>
  <option value = "Budget">Budget</option>
  <option value = "Multi">Multi-Fuel</option>
  <option value = "Wood"> Wood</option>
  <option value = "Gas">Gas</option>
  <option value = "Inset">Inset</option>
  <option value = "Boiler">Boiler</option>
  <option value = "double-sided">Double-Sided</option>
  <option value = "contemporary">Comtenporary</option>
  <option value = "flue gas">Flue Gas</option>
  <option value = "flueless gas">Flueless Gas</option>
  <option value = "electric">Electric</option>
  <option value = "smoke controlled">Smoke Controlled</option>
  <option value = "oil">Oil</option>
  <option value = "pellet">Pellet</option>
  <option value = "Pot Belly">Pot Belly</option>  
  </select>
  </td></div>
  </tr>
  <input type="image" src= "search button.jpg" align="middle"/>
  </form>
  <form  method="post" action="manufacturersearch.php"  id="manufacturerselect">
  <table width="80%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
    <td>&nbsp;</td>
    </tr>
    <tr>
      <td width="12%" background="sidemenubar2.jpg"> <div align="center" class="style10">
        <div align="center" class="style12">MANUFACTURERS</div>
      </div></td>
      </tr>
    </table>

<tr><div>
<td width="100%"><select name="manufacturer" size="1" value="">
  <option selected>Please Select</option>
<? $i=0; while ($i<$num)
{$manufacturers=mysql_result($result,$i,"manufacturer");
echo "<option>$manufacturers</option>";
$i++; }
?>
</select></div></td>
</tr>
  <input type="image" src= "search button.jpg" align="middle"/>
  </form>
  <form  method="post" action="priceselect.php"  id="priceselect">
  <table width="80%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
  <td>&nbsp;</td>
  </tr>
    <tr>
      <td width="12%" background="sidemenubar2.jpg"> <div align="center" class="style10">
        <div align="center" class="style12">SEARCH BY PRICE</div>
      </div></td>
      </tr>
    </table>
    <tr>
<td width="100%"><div><select name="price" size="1" value="<? $priceselect?>">
  <option value="" selected>Please Select</option>
  <option vslue ="price1">£100 - £200</option>
  <option value ="price2">£201 - £300</option>
  <option value ="price3">£301 - £400</option>
  <option value ="price4">£401 - £500</option>
  <option value ="price5">£501 - £600</option>
  <option value ="price6">£601 - £700</option>
  <option value ="price7">£701 - £800</option>
  <option value ="price8">£801 - £900</option>
  <option value ="price9">£901 - £1000</option>
  <option value ="price10">OVER £1000</option>
  </select></div>
  </tr>
  <input type="image" src= "search button.jpg" align="middle"/>
  </form>
  <form  method="post" action="heatoutputselect.php"  id="heatoutputselect">
  <table width="80%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
  <td>&nbsp;</td>
  </tr>
    <tr>
      <td width="12%" background="sidemenubar2.jpg"> <div align="center" class="style10">
        <div align="center" class="style12">HEAT OUTPUT</div>
      </div></td>
      </tr>
    </table>
    <tr>
<td width="100%"><div><select name="HEAT" size="1" value="<? $heatselect?>">
  <option value="" selected>Please Select</option>
  <option value  ="3">3KW</option>
  <option value ="4">4KW</option>
  <option value ="5">5KW</option>
  <option value ="6">6KW</option>
  <option value ="7">7KW</option>
  <option value ="8">8KW</option>
  <option value ="9">9KW</option>	
  <option value ="10">10KW</option>
  </select></div>
  </tr>
  <input type="image" src= "search button.jpg" align="middle"/>
  </form>
  <table width="80%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
  <td>&nbsp;</td>
  </tr>
    <tr>
      <td width="12%" background="sidemenubar2.jpg"> <div align="center" class="style10">
        <div align="center" class="style12">INFORMATION</div>
      </div></td>
      </tr>
      <tr>
      <td><div align="left"><span class="style13">Installation</span></div></td>
      </tr>
      <tr>
      <td><div align="left"><span class="style13">CopyRight</span></div></td>
      </tr>
      <tr>
      <td><div align="left"><span class="style13">Conditions</span></div></td>
      </tr>
      <tr>
      <td><div align="left"><span class="style13">Contact</span></div></td>
      </tr>
      <tr>
      <td><div align="left"><span class="style13">Customer Comments</span></div></td>
      </tr>
      <tr>
      <td><div align="left"><span class="style13">Help and Advide</span></div></td>
      </tr>
      <tr>
      <td><div align="left"><span class="style13">Understanding the website</span></div></td>
    </table>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
</div>
  <div id="sidebar2">
    <!-- end #sidebar2 -->
    <table width="69%" border="0" align="right" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF" bgcolor="#FFFFFF">
      <tr>
        <td><div align="right"><a href="index.html"><img src="newmemberbutton.jpg" width="130" height="43" /></a></div></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td><div align="right"><a href="index.html"><img src="loginbutton.jpg" width="130" height="43" /></a></div></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td><div align="right"><a href="index.html"><img src="BASKETBUTTON.jpg" width="130" height="43" /></a></div></td>
      </tr>
    </table>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
</div>
  <div id="mainContent">
   <p>
<?php
$i=0; while ($i<$stovenum)
{
$name = mysql_result($stoveresult,$i,"Product_Name");
$image = imagecreatefromstring(mysql_result($stoveresult,$i,"Picture_Thumb"));
$price = mysql_result($stoveresult,$i,"product_price");
echo "$name \n<br>";
header('Content-type: image/jpeg');
imagejpeg($image);
imagedestroy($image);
echo "$price \n<br>";
$i++;}mysql_close(); 
?>
</p>
   </div>
	<!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --><br class="clearfloat" />
   <div id="footer">
    <p align="left" class="style11">&copy; <a href="www.bitsconsultancyuk.co.uk">designed by B.I.T.S Consultancy UK</a></p>
<!-- end #footer --></div>
<!-- end #container --></div>
</body>
</html>

I have included my code for the page which the image needs to be displayed to the php for connecting and running the query is near the top of the code whilst the php for displaying the image is near the bottom of the code. As I say am a bit rusty so have probably made a right mess from start to finish but everything but the image is working. If anyone can help me get past this problem would be much appreciated

thanks Scott