andy_b_1502 Posted February 12, 2012 Share Posted February 12, 2012 My photo files are not being displayed in my table? They get sent to the mySQL database, then the server and it does grab all the other variables in the table and displays them, but the .jpg's are not shown, instead theres just the file name?? <?php error_reporting(E_ALL); ini_set("display_errors", 1); echo '<pre>' . print_r($_FILES, true) . '</pre>'; //This is the directory where images will be saved $target = "/home/users/web/b109/ipg.removalspacecom/images/COMPANIES"; $target = $target . basename( $_FILES['upload']['name']); //This gets all the other information from the form $company_name=$_POST['company_name']; $basicpackage_description=$_POST['basicpackage_description']; $location=$_POST['location']; $postcode=$_POST['postcode']; $upload=($_FILES['upload']['name']); // Connects to your Database mysql_connect("server****", "username***", "password****") or die(mysql_error()) ; mysql_select_db("DB") or die(mysql_error()) ; //Writes the information to the database mysql_query("INSERT INTO `Companies` (company_name, basicpackage_description, location, postcode, upload) VALUES ('$company_name', '$basicpackage_description', '$location', '$postcode', '$upload')") ; echo mysql_error(); //Writes the photo to the server if(move_uploaded_file($_FILES['upload']['tmp_name'], $target)) { //Tells you if its all ok echo "The file ". basename( $_FILES['upload']['name']). " has been uploaded, and your information has been added to the directory"; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } ?> "upload" is the variable that isnt displaying in my table how i want it to? Have you guys any ideas how to get it displayed correctly? Quote Link to comment https://forums.phpfreaks.com/topic/256931-display-uploaded-photos/ Share on other sites More sharing options...
litebearer Posted February 12, 2012 Share Posted February 12, 2012 do you mean the field for the image in your DATABASE table is empty? Quote Link to comment https://forums.phpfreaks.com/topic/256931-display-uploaded-photos/#findComment-1317224 Share on other sites More sharing options...
andy_b_1502 Posted February 12, 2012 Author Share Posted February 12, 2012 no it's not empty? it has the actual name of the .jpg file. in this case 360mainhead.jpg in the table: http://www.removalspace.com/index.php it should have the attached image showing instead Quote Link to comment https://forums.phpfreaks.com/topic/256931-display-uploaded-photos/#findComment-1317228 Share on other sites More sharing options...
scootstah Posted February 12, 2012 Share Posted February 12, 2012 That's because you're storing the name, not the image. You need to put the database result in image tags, and point it to where the image is located on the server. Quote Link to comment https://forums.phpfreaks.com/topic/256931-display-uploaded-photos/#findComment-1317230 Share on other sites More sharing options...
litebearer Posted February 12, 2012 Share Posted February 12, 2012 Expanding upon what scoots said... The code you provided above is for uploading and storing the information; NOW you need to write a script that retrieves and displays the information. Quote Link to comment https://forums.phpfreaks.com/topic/256931-display-uploaded-photos/#findComment-1317231 Share on other sites More sharing options...
andy_b_1502 Posted February 13, 2012 Author Share Posted February 13, 2012 i have this so far, it shows all of the table, which is what i want all except the images i've had a look for a possible answer and added the path to the image folder on my server but it doesn't seem to work, how can i get this to show the images from the folder on the server? <?php // Make a MySQL Connection mysql_connect("server", "user", "password") or die(mysql_error()); mysql_select_db("my_DB") or die(mysql_error()); // Retrieve all the data from the "example" table $result = mysql_query("SELECT company_name, location, postcode, basicpackage_description, premiumuser_description, upload FROM Companies") or die(mysql_error()); // store the records of the "TABLENAME" table into $row array and loop through while ( $row = mysql_fetch_array( $result, MYSQL_ASSOC ) ) { // Print out the contents of the entry echo "details: ".$row['details']; echo "<img src=\"/home/users/web/b109/ipg.removalspacecom/images/COMPANIES".$row['image1']."\" alt=\"name\" />"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/256931-display-uploaded-photos/#findComment-1317747 Share on other sites More sharing options...
scootstah Posted February 13, 2012 Share Posted February 13, 2012 You need the HTTP location, not the physical file location. example.com/images/blah.jpg Quote Link to comment https://forums.phpfreaks.com/topic/256931-display-uploaded-photos/#findComment-1317782 Share on other sites More sharing options...
litebearer Posted February 13, 2012 Share Posted February 13, 2012 btw $row['image1'] will not show the image because image1 was NOT one of the fields you asked for in your query Quote Link to comment https://forums.phpfreaks.com/topic/256931-display-uploaded-photos/#findComment-1317793 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.