steve490 Posted February 9, 2010 Share Posted February 9, 2010 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 More sharing options...
alexjb Posted February 9, 2010 Share Posted February 9, 2010 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. Link to comment https://forums.phpfreaks.com/topic/191489-image-problem-prob-simple-solution/#findComment-1009435 Share on other sites More sharing options...
Buddski Posted February 9, 2010 Share Posted February 9, 2010 Not only as alexjb has said about uploadedinfo but you <img> tag could do with some compliance.. it may fix your browser issue.. Link to comment https://forums.phpfreaks.com/topic/191489-image-problem-prob-simple-solution/#findComment-1009438 Share on other sites More sharing options...
steve490 Posted February 9, 2010 Author Share Posted February 9, 2010 cheers guys worked like a charm After about 10 different uploads lol, I found that I cant upload any images that have a space in there name (which some pictures have). Is there anyway round this problem? Link to comment https://forums.phpfreaks.com/topic/191489-image-problem-prob-simple-solution/#findComment-1009475 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.