Revolutsio Posted May 16, 2022 Share Posted May 16, 2022 I have a small database and was wondering how i add images from a server (my hdd) I have field the database with the following fields .id .song name .artist .track 1 .track 2 .track 3 .image i have entered in about 10 entries in the database but do not know how to upload images to image field How can i do this (all the webpages that i have searched show how to add images but not in the order i would like) i have no code yet Quote Link to comment https://forums.phpfreaks.com/topic/314800-how-to-upload-images-to-server-and-the-end-of-a-database/ Share on other sites More sharing options...
Barand Posted May 16, 2022 Share Posted May 16, 2022 Don't store the image in the database, just store its name (or path/name). On output use an HTML <img> tag to display the image from your server. Quote Link to comment https://forums.phpfreaks.com/topic/314800-how-to-upload-images-to-server-and-the-end-of-a-database/#findComment-1596315 Share on other sites More sharing options...
Revolutsio Posted May 16, 2022 Author Share Posted May 16, 2022 Thank you for your reply. I have tried this but cannot get it add the filename to the database. here is the code <html> <body> <form method="POST" action="upload.php" enctype="multipart/form-data"> <input type="file" name="image"> <input type="submit" name="submit_image" value="Upload"> </form> <?php $conn = mysqli_connect("localhost","root","","gameslibrary"); if(isset($_POST['image'])) { $Get_image_name = $_FILES['image']['name']; $image_path = "upload/".basename($Get_image_name); $sql = "INSERT INTO test (image, contact) VALUES ('$Get_image_name' 'USA')"; mysqli_query($conn, $sql); if(move_uploaded_file($_FILES['image']['tmp_name'], $image_path)) { echo "Your Image uploaded successfully"; }else { echo "Not Insert Image"; } } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/314800-how-to-upload-images-to-server-and-the-end-of-a-database/#findComment-1596318 Share on other sites More sharing options...
Barand Posted May 16, 2022 Share Posted May 16, 2022 Check for MySQL errors. Quote Link to comment https://forums.phpfreaks.com/topic/314800-how-to-upload-images-to-server-and-the-end-of-a-database/#findComment-1596319 Share on other sites More sharing options...
Revolutsio Posted May 16, 2022 Author Share Posted May 16, 2022 Thank you for your replay, I have found a way to add the images to my database. could anybody tell me how to show the image on my page <?php foreach($games as $game): ?> <!-- this is where the screenshot will go --> <!-- <img src="images/2.png"> --> <img src=<?php echo $game['id']?><?php echo <img src="uploads/ . $game['image']> ?> <a href="details.php?id=<?php echo $game['id']?>"><?php echo $game['game']?></a> Quote Link to comment https://forums.phpfreaks.com/topic/314800-how-to-upload-images-to-server-and-the-end-of-a-database/#findComment-1596320 Share on other sites More sharing options...
Barand Posted May 16, 2022 Share Posted May 16, 2022 What does your table contain in the "image" column? What folder are your images in? (Your code is ambiguous in this respect) Quote Link to comment https://forums.phpfreaks.com/topic/314800-how-to-upload-images-to-server-and-the-end-of-a-database/#findComment-1596322 Share on other sites More sharing options...
Revolutsio Posted May 17, 2022 Author Share Posted May 17, 2022 Thank you for your reply sorry for the late respond. I got it to work Thank you Quote Link to comment https://forums.phpfreaks.com/topic/314800-how-to-upload-images-to-server-and-the-end-of-a-database/#findComment-1596387 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.