Hi I am having some trouble displaying images stored as a blob in a mysql database. When I run the script the image locatioon is printed out but not the image.

<?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_array($result)) {

echo "<p>You searched for: &quot;" . $myq . "&quot;</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 $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();
?>

    Out of curiosity, why do you have it as a blob? Performance wise, it's generally easier to store the image on the server and then have a field that contains the image path.

      Hi, i have an upload feature for users, and i was told to store the images in the database as a blob, can i store them on the server, if so how do i direct the images to a folder?

        Here is my load in file:

        <html>
        <head>
        <title>Car Rentals & Returns</title>
        <meta http-equiv="Content-Type" content="text/html" />
        <link href="style2.css" rel="stylesheet" type="text/css" />
        </head>
        <body>
        <div id="wrapper3">
        <img src="images/cars.jpg" width="996" height="100"></a>

        <TABLE BGCOLOR="#F0F8FF" BORDER=0 CELLPADDING=10 WIDTH=100%>
        <tr>
        <td align="center">
        <H1>Add new car</H1>
        </td></tr>

        <tr><td>
        <h2>Please upload a new picture</h2>

        <form action="carimage.php" method="post">

        <input type=hidden name=MAX_FILE_SIZE value=150000>

        <input type=hidden name=completed value=1>

        Please choose an image to upload: <input type=file name=myimage><br>
        <br>

        Please enter the car registration: <input name=myreg><br>
        <br>

        Please enter the car make: <input name=mymake><br><br>

        <input type=submit value="Add Car"></form>
        <form action="login_success3.php" method="post">
        <input type=submit value="Home"></form><br>
        </td></tr>
        </body>
        </html>

          Write a Reply...