Jump to content

Recommended Posts

ok, so I have a form that is submitted to the DB containing client info and a thumbnail.  I also have a program that calls the data from the DB and displays the info in a table.  The problem I am having is in displaying the thumbnail.  It just displays a lot of code that i guess makes up the image.  Anyways, below is my code.  Any help would be great.  Thanks.

 

the upload form

<?php 
  include ("db.inc");
  
  $connection = mysql_connect($host, $user, $password) or die ("Couldn't connect to the server");
  $db = mysql_select_db($database, $connection) or die("could not select the DB");
  $companyName = Trim(stripslashes($_POST['companyName']));
  $companyWeb = Trim(stripslashes($_POST['companyWeb']));
  
 $fileName = $_FILES['userfile']['name'];
$tmpName  = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

$fp      = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);

if(!get_magic_quotes_gpc())
{
    	$fileName = addslashes($fileName);
}

  $sql = "INSERT INTO ClientList (companyName, companyWeb, name, size, type, content) VALUES ('$companyName', '$companyWeb', '$fileName', '$fileSize', '$fileType', '$content')";
  $result = mysql_query($sql) or die ("Could not execute query");

  if($result == "yes")
  {
  header("Location: viewclient.php");
  echo "Client Successfully Added";
  exit;
  }
  
?>

 

the view the data code

 

<?php
  include("db.inc");
  
  $connection = mysql_connect($host, $user, $password) or die ("Could not connect");
  $db = mysql_select_db($database, $connection) or die ("Could not connect to DB");
  if ($_POST['delete']){
  	$deleteID = $_POST['delete'];
	mysql_query("DELETE FROM ClientList WHERE companyName = '$deleteID'") or die (mysql_error());
	echo "Successfully Deleted Client<p>";
}
  $sql = "SELECT * FROM ClientList ORDER BY companyName";
  $result = mysql_query($sql) or die("Could not execute query");
  
  echo "<table cellpadding='0' border='1' cellspacing='0' width='500' align='center'>";
  echo "<tr><td><font size='-2'>Press Below Button to Delete</font></td><td>Company Name</td>";
  echo "<td>Company Web Site</td><td>Thumbnail</td></tr>";
  while ($row = mysql_fetch_array($result))
  	{
		extract($row);
		echo "<tr><td align='center'><form id='form1' name='form1' method='post' action='{$_SERVER['PHP_SELF']}'><input type='submit' name='delete' value='{$row['companyName']}' /></form><td>";
		echo $companyName."</td>";
		echo "<td><a href='http://".$companyWeb."' target='_blank'>".$companyWeb."</a></td>";
		echo $content;
		echo "</tr>";
	}
	echo "</table>";
?>

Link to comment
https://forums.phpfreaks.com/topic/40771-displaying-images-from-a-db/
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.