I tried to upload and display an image from a particular row in mysql. The upload was ok cause the image file was sent to the folder. However, the image would not display instead X was diplayed at the image position. Other informations were displayed correctly.Could it be that my path was not correctly defined. Could someone help me .Thanks in anticipation. Here is the code.
<?php
//This is the directory where images will be saved
$ran = rand () ;
$ran2 = $ran.".";
$target = "images/";
$target = $target .$ran2. basename( $_FILES['photo']['name']);
$ok=1;
//This gets all the other information from the form
$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$pic=($_FILES['photo']['name']);
// Connects to your Database
mysql_connect("localhost", "###", "####") or die(mysql_error()) ;
mysql_select_db("####") or die(mysql_error()) ;
//Writes the information to the database
mysql_query("INSERT INTO `table` (`name`, `email`,`phone`,`photo`) VALUES ('$name', '$email', '$phone', '$pic')") ;
$id= mysql_insert_id();
//This is our size condition
if ($uploaded_size > 35000)
{
echo "Your file is too large.<br>";
$ok=0;
}
//This is our limit file type condition
if ($uploaded_type =="text/php")
{
echo "No PHP files<br>";
$ok=0;
}
//Here we check that $ok was not set to 0 by an error
if ($ok==0)
{
Echo "Sorry your file was not uploaded";
}
//If everything is ok we try to upload it
else
//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{
//Tells you if its all ok
echo "The file ". basename( $_FILES['photo']['name']). " has been uploaded, and your information has been added to the directory";
echo " Your Registration Form Number is . $id ";}
else {
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";}
$query = "SELECT * FROM table WHERE id=$id";
$result = mysql_query($query)or die(mysql_error());
while($row = mysql_fetch_array($result)) {
echo "<p>FORM NUMBER :62RRI/ <b>".$id."</b><br><br>";
echo "<img src=http://localhost/army/$target".$row['photo']."> <br>"or die(mysql_error());
echo "<p>Name: <b>".$row['name']."</b><br>";
echo "<p>E-Mail: <b>".$row['email']."</b><br>";
echo "<p>Phone Number: <b>".$row['phone']."</b><p>";
echo "<p>Your Photo: <b>".$row['photo']."</b><p>";
}
?>