Jump to content

displaying an image from mysql database using php


kirigwajo

Recommended Posts

i have a database named  "child" a table "jpg" with column names;  pid, title and imgdata.

 

i have managed to get images into the database but now i want to be able to call the images using "title"

 

The code i have displays the image last added to the Mysql database.

 

This is the code that where i have to enter the variable for "title" to display the image.

 

<html>
<body bgcolor=#afd1f4>

<table border='1' bgcolor=#7991d4 frame=lhs cellpadding="4" width=100%>
<tr bgcolor=#cbe0ac ><td><font face='Vinque'><B>SEARCH FOR A CHILD PHOTO</B></TR>
<tr><td><p align="center"><font size="4" face="Vinque">

<form action="jpgshow.php" method="POST">

<p align="center"><font size="4" face="">
CHILD NAME:<br/>
<input  type="text"  name="title" size="30" /><br/>
<div align="center"><input type="submit" name="submit" value= "Find" />
<input type="reset" name="Clear" value= "Clear" />
</div>
</form

><legend><table border='1' bgcolor=d4ecfb frame=lhs cellpadding="4" width=100%><tr><td>
<title>Search Results</title></head><h4><p align="center"><font size="5">SEARCH RESULTS</font></h4></p>
<br/>

<?php
$pid=$_POST['pid'];
$title=$_POST['title'];
$imgdata=$_POST['imgdata'];

$server = 'localhost';
$dbuser="root";
$dbpasswd="";
// Make a MySQL Connection
mysql_connect($server , $dbuser , $dbpasswd) or die(mysql_error());
mysql_select_db("child") or die(mysql_error());

// Get all the data from the "jpg" table

$bytes = $row[imgdata];
echo $imgdata;
print $bytes;

$select=("select pid,title from jpg where title='$title'");
$result=mysql_query($select);
while($info=mysql_fetch_array($result)){
echo '
</table>';
}

?>
<img src="jpgshow.php?pid=<?php echo $pid ?>">



<form action="child.html" method="POST">
<div align="left"><input type="submit" name="submit" value=" Back" />

</legend></body></html>


this is the code for that displays the image last entered in database.

<?php
$username="root";
$password="";
$database="child";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die("<b>Unable to specified database</b>");

$image = stripslashes($_REQUEST[title]);
$gotten = @mysql_query("select * from jpg order by pid desc limit 1");
addslashes($image).".jpg\"";
$row = @mysql_fetch_assoc($gotten);
$imagebytes = $row[imgdata];
header("Content-type: image/jpeg");
print $imagebytes;



?>

please help me.

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.