mjgdunne Posted April 20, 2008 Share Posted April 20, 2008 Hi i have stored information into mysql database, when i do a search for the using the title or reg of the car the image does not display is there anything else i need to add to get this to display. The images are displayed as longblob attributes binary. Any help would be great thanks. <?php session_start(); ini_set( 'display_errors', '1' ); error_reporting ( 2047 ); $host="localhost"; // Host name $username="root"; // Mysql username $password="root"; // Mysql password $db_name="test"; // Database name $tbl_name="pix"; // Table name // Connect to server and select databse. mysql_connect("$host", "root", "root")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $myq=$_POST['myq']; if (isset($_POST['myq'])) { $myq = mysql_real_escape_string($_POST['myq']); $result = mysql_query("SELECT * FROM pix WHERE title LIKE '%$myq' OR registration LIKE '%$myq'"); while ($row = mysql_fetch_assoc($result)) { echo "<p>You searched for: "" . $myq . ""</p>"; echo "<table border=\"1\" align=\"center\">"; echo "<tr><th>Car Make</th>"; echo "<td>"; echo $row['title']; echo "</td>"; echo "<tr><th>Image</th>"; echo "<td>"; echo '<img src="'.$row['imgdata'].'"/>'; echo "</td>"; echo "<tr><th>Registration</th>"; echo "<td>"; echo $row['registration']; echo "</td>"; } } if (!$result) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query; die($message); } if (mysql_num_rows($result) == 0) { echo "No records found"; exit; } exit(); ?> Link to comment https://forums.phpfreaks.com/topic/102021-displaying-image-from-mysql-database/ Share on other sites More sharing options...
dptr1988 Posted April 20, 2008 Share Posted April 20, 2008 You can't embed images into HTML. The 'src' attribute for the img tag need to be a link to a PHP script that will retrieve the image data from the database and output it to the browser. Link to comment https://forums.phpfreaks.com/topic/102021-displaying-image-from-mysql-database/#findComment-522155 Share on other sites More sharing options...
mjgdunne Posted April 20, 2008 Author Share Posted April 20, 2008 I new to php programming, so i cant just do a echo and print out the image no? How would i go about getting it to work? Link to comment https://forums.phpfreaks.com/topic/102021-displaying-image-from-mysql-database/#findComment-522160 Share on other sites More sharing options...
dptr1988 Posted April 20, 2008 Share Posted April 20, 2008 Read though the instructions here at http://www.phpriot.com/articles/images-in-mysql, espcially page 8. This describe what I was saying you should do. Link to comment https://forums.phpfreaks.com/topic/102021-displaying-image-from-mysql-database/#findComment-522169 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.