The codes:
<!DOCTYPE HTML>
<html>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
ID:<br><input type="varchar" name="id">
<input type="submit" name="submit" value="Search">
</form>
<?php
$db_host = "localhost";
$db_username = "root";
$db_pass = "usbw";
$db_name = "image";
@mysql_connect ("$db_host", "$db_username", "$db_pass") or die ("Could not connect to MySQL");
@mysql_select_db("$db_name") or die ("No database");
if(isset($_POST['submit'])) {
//id no sent from form
$id=$_POST['id'];
// To protect MySQL injection
$id= stripslashes($id);
$id= mysql_real_escape_string($id);
$data=mysql_query("SELECT * FROM img WHERE id='$id'");
if ($row = mysql_fetch_array($data)) {
$photo = $row['path'];
echo "<style='text-align:center'><center><img src=$photo alt=Profile Photo height=300px
width=300px></center>"."</br>";
}
}
?>
</body>
</html>
Lets test the code!
No comments:
Post a Comment