Jump to content

displaying image from mysql database


mjgdunne

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.