Searching Images using PHP

To search images using PHP from MySQL Database, follow the examples.

First of all create a table in MySQL database with following fields.

Now, insert some images by clicking on “insert” tab in MySQL.

Now, create a HTML page as following tags.

<h1> Image searching.........</h1>
<form name=f1 action="image.php" method="GET">
Enter image Id: <input type=text name=t1>
<input type=submit value="Display"> 

After creating above HTML page, now create PHP config file with following code in it.[save as “config.php”] this file contains database name, user, password etc.


Now create PHP file to search stored images in database.
Copy the following code and save as “image.php”.

include './config.php';
@mysql_connect($host, $username, $password) or die("Can not connect to database: ".mysql_error());

@mysql_select_db($dbname) or die("Can not select the database: ".mysql_error());

$query = mysql_query("SELECT * FROM photo WHERE pid=' ".$key."'");

$row = mysql_fetch_assoc($query);

$contents = $row['content'];

header("Content-type: image/jpg");
echo $contents;

Now, run HTML page as following.

Finally the output looks like this.

That’s all for now!, Thank you for reading!