title: Image from database is not displaying on webpage
body: <p>so I have this blog that I am creating, but I am having issues with displaying an image from a database to the page itself. It only comes up with a broken image. The data does appear in the database however. It just doesn't display on the page.  </p>
  
  <p>Here is the image.php code (used to display the text and images): </p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  &lt;?php
  //connect to database
  
  //Name the variables
  $host= "localhost";
  //Localhost is the name of the computer that USBWebser has been loaded on
  $username = "user";
  $password = "pwd";
  $database = "blog";
  
  $dbh=mysql_connect("$host", "$username", "$password") or die('Could not connect:' .mysql_error());
  
  //if cannot connect to database display error message
  if(!$dbh)
  {
  echo mysql_error();
  }
  
  mysql_select_db("$database");
  
  //get the id number of the row that the photo is located in and place it in $ano
  $ano=$_GET['postID'];
  
  //select the data and type for the photo identified by id
  $sql="SELECT photo, phototype FROM blog where postID='$ano'";
  
  //check if sql query can be executed
  $r=mysql_query($sql, $dbh);
  
  //if sql query can be executed
  if($r)
  {
  
  //get the data from the query
  $row=mysql_fetch_array($r);
  
  //set the header information so that an image can be displayed
  $type="Content-type: image/png" .$row['phototype'];
  header($type);
  
  //display the image
  echo $row['photo'];
  }
  else
  {
  echo mysql_error();
  }
  
  ?&gt;
  </code></pre>
  
  <p>Here is the code for the main_menu.php (where I would like the image to appear) </p>
  
  <pre><code>&lt;?PHP
  //Name the variables
  $host= "localhost";
  //Localhost is the name of the computer that USBWebser has been loaded on
  $username = "user";
  $password = "pwd";
  $database = "blog";
  
  $mysqli=new mysqli($host, $username, $password, $database);
  
  //Connect to Header
  include "header.php";
  ?&gt;
  &lt;?php
  //Select fields from the posts table
  $sql="SELECT postID, title, date, contents, rating, photo, phototype FROM posts";
  //Place the data into a variable named $result
  $result= $mysqli-&gt;query($sql);
  
  if ($result-&gt;num_rows&gt;0){
  
  while ($row=$result-&gt;fetch_assoc()) {
  ?&gt;
  &lt;br&gt;&lt;table border="1" bordercolor="25dae3" width="53%"&gt;&lt;th&gt;&lt;font color="white"&gt;Title&lt;/th&gt;&lt;th&gt;&lt;font color="white"&gt;Date&lt;/th&gt;&lt;th&gt;&lt;font color="white"&gt;Contents&lt;/th&gt;&lt;th&gt;&lt;font color="white"&gt;Image&lt;/th&gt;&lt;th&gt;&lt;font color="white"&gt;Rating&lt;/th&gt;
  &lt;tr&gt;&lt;td width = "100" align="center"&gt;&lt;font color="white"&gt;
  &lt;?php 
  echo $row["title"];
  ?&gt;
  &lt;/td&gt;
  &lt;br&gt;&lt;td width="100" align="center"&gt;&lt;font color="white"&gt;
  &lt;?php
  echo $row["date"];
  ?&gt;
  &lt;/td&gt;
  &lt;br&gt;&lt;td width="300" align="center"&gt;&lt;font color="white"&gt;
  &lt;?php
  echo $row["contents"];
  ?&gt;
  &lt;/td&gt;
  &lt;br&gt;&lt;td width="300" align="center"&gt;&lt;font color="white"&gt;
  &lt;img src="&lt;?php echo $row['photo']; ?&gt;" width=300 height=300/&gt;;
  &lt;/td&gt;
  &lt;br&gt;&lt;td width="100" align="center"&gt;&lt;font color="white"&gt;
  &lt;?php
  echo $row["rating"];
  ?&gt;
  &lt;/td&gt;&lt;/tr&gt;&lt;/font&gt;
  &lt;?php
  }
  } else {
      //Display message that no data was present
      echo "0 results";
  }
  //Close connection
  $mysqli-&gt;close();
  ?&gt;
  </code></pre>
  
  <p>The add_post.php </p>
  
  <pre><code>&lt;html&gt;
  &lt;header&gt;
  &lt;/header&gt;
  &lt;body&gt;
  &lt;?php
  //Name the variables
  $host = "localhost";
  //Localhost is the name of the computer that USBWebserver has been loaded on 
  $username = "user";
  $password = "pwd";
  $database = "blog";
  
  $mysqli=new mysqli($host, $username, $password, $database);
  
  //Get variables from the form 
  $new_post_title=$_POST["newtitle"];
  $new_post_date=$_POST["newdate"];
  $new_post_contents=$_POST["newcontents"];
  $new_post_rating=$_POST["newrating"];
  $photo=addslashes(file_get_contents($_FILES["photo"]["tmp_name"]));
  $imagesize=getimagesize($_FILES["photo"]["tmp_name"]); 
  
  //mime returns the image time eg. image/jpeg
  $imagetype=$imagesize['mime'];
  
  //Enable sql to read quotation marks within sentences
  $new_post_title=addslashes($new_post_title);
  $new_post_date=addslashes($new_post_date);
  $new_post_contents=addslashes($new_post_contents);
  $new_post_rating=addslashes($new_post_rating);
  
  //Enter the new information into the posts table 
  $sql="INSERT INTO posts(postID, title, date, contents, rating, photo, phototype) VALUES (Null, '$new_post_title', '$new_post_date', '$new_post_contents', '$new_post_rating', '$photo', '$imagetype')"; 
  
  //Run the query 
  $result=$mysqli-&gt;query($sql) or die (mysqli_error($mysqli)); 
  
  if ($result) {
  
  header ('location:main_menu.php');
  }
  
  else {
  echo mysql_error();
  }
  ?&gt; 
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And the form to submit a post to the blog (add_new_post.php)</p>
  
  <pre><code>&lt;HTML&gt;
  &lt;style&gt;
  form {
      border-opacity: 1.0 ;
      display: incline-block;
      text-align: center;
  }
  
  input[type=text]:focus, input[type=date]:focus {
  width: 50%;
  height: 20%;     
  border: 3px solid #00ffff;   
  }
  
  body {
     text-align: center;
     padding-top: 50px; 
   }
  
  &lt;/style&gt;
  &lt;HEAD&gt;
  &lt;/HEAD&gt;
  &lt;BODY&gt;&lt;font color="white"&gt;
  &lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;H1 text-align="center"&gt;Add a New Post&lt;/H1&gt;
  &lt;?php 
  //Connect To Header Page
  include "header1.php";
  
  //Connect To Database
  include "dbconnect.php";
  ?&gt;
  &lt;br&gt;
  &lt;br&gt;
  &lt;!-- &lt;HR&gt; Tag inserts a horizonal line across the page (horizontal rule)--&gt;
  &lt;!-- &lt;Form&gt; Tag indicates that a form will be created --&gt;
  &lt;!-- action indicates the file used to process the input when the submit button is pressed--&gt;
  &lt;form enctype= "multipart/form-data" action="add_post.php" method = "POST"&gt;
  Title: &lt;br&gt;
  &lt;!-- &lt;input type&gt; Tag indicates the type of input expected eg. text. Name = indicates the name given to the input--&gt;
  &lt;input type="text" name="newtitle"&gt;&lt;br&gt;
  Date: &lt;br&gt;
  &lt;input type="date" name="newdate"&gt;&lt;br&gt;
  Contents: &lt;br&gt;
  &lt;input type="text" name="newcontents"&gt;&lt;br&gt;
  Rating: &lt;br&gt;
  &lt;input type="text" name="newrating"&gt;&lt;br&gt;
  Please Browse to where the photo is located:&lt;br&gt; 
  &lt;input type = file name = "photo"&gt;&lt;br&gt;
  &lt;br&gt;
  &lt;!-- Value indicates the text to be displayed. In this case, displayed on the button --&gt;
  &lt;input type ="submit" value="Submit"&gt;
  &lt;/form&gt;
  &lt;/BODY&gt;
  &lt;/HTML&gt;
  </code></pre>
  
  <p>Any assistance on this issue would be appreciated. </p>
  
  <p>Thanks</p>