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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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