Jump to content

Image problem prob simple solution


steve490

Recommended Posts

Hey there,

 

When I try and display pictures on my website from the server and database they seem to appear as the same image even though the file names are displaying different, so img2 will display the same image as img1. Here's my upload and the method im using to call the pictures from the database and server:-

 

 

$conn2 = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

$dbname = '****';
mysql_select_db($dbname);

{
$target_path = "uploads/";


$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

$pic = ($_FILES['uploadedfile']['name']);


mysql_query ("INSERT INTO img (name, email) VALUES ('uploads/$pic','$_SESSION[email]')");


if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
   " has been uploaded to" . $target_path;
} else{
    echo "There was an error uploading the file, please try again!";
}


$image_viewer = "SELECT * FROM img WHERE email='$_SESSION[email]'";

$show_image = mysql_query($image_viewer);

mysql_close($conn2)

 

This is where im calling the pictures from the server and database

 

while($info = mysql_fetch_array( $show_image ))
{

//Outputs the images

echo "<img src=/uploads/$pic".$info['uploadedfile'] ."> <br>";
echo "<b>Name:</b> ".$info['name'] . "<br> "; 

}

 

Also the pictures only display in Firefox

 

cheers for the help

Link to comment
https://forums.phpfreaks.com/topic/191489-image-problem-prob-simple-solution/
Share on other sites

Is 'uploadedfile' the correct column name in your picture table? My guess would be $info['uploadedfile'] is empty, and thus its just using the $pic variable, which isn't changing throughout the loop. Try:

 

while($info = mysql_fetch_array( $show_image ))
{

//Outputs the images

echo "<img src=/".$info['name'] ."> <br>";
echo "<b>Name:</b> ".$info['name'] . "<br> "; 

}

 

If it doesn't work I need more information, such as the structure of your image table.

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.