I use the analog of this code https://codewithawa.com/posts/image-...mysql-database trying to load and output the image from the database to the page ... Allows you to choose, DOWNLOADS in dB, but returns the picture and shows that it is The type is broken, and the text that you enter - displays. Already the third day I can not understand what the error is ... I think that somewhere after the cycle, in the line where the output of the picture is, but everything seems to be correct ... Thanks in advance

<?php // Create database connection $db = mysqli_connect("localhost", "root", "", "image_upload"); // Initialize message variable $msg = ""; // If upload button is clicked ... if (isset($_POST['upload'])) { // Get image name $image = $_FILES['image']['name']; // Get text $image_text = mysqli_real_escape_string($db, $_POST['image_text']); // image file directory $target = "images/"."image_upload($image)"; $sql = "INSERT INTO images (image, image_text) VALUES ('$image', '$image_text')"; // execute query mysqli_query($db, $sql); if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) { $msg = "Image uploaded successfully"; }else{ $msg = "Failed to upload image"; } } $result = mysqli_query($db, "SELECT * FROM images"); ?> <!DOCTYPE html> <html> <head> <title>Image Upload</title> </head> <body> <div id="content"> <?php while (($row=$result->fetch_assoc())!=false) { echo '<div id="img_div"> <img src="images/'.$row["image"].'" > <p>'.$row['image_text'].'</p> </div>'; } ?> <form method="POST" action="kartinka.php" enctype="multipart/form-data"> <input type="hidden" name="size" value="1000000"> <div> <input type="file" name="image"> </div> <div> <textarea id="text" cols="40" rows="4" name="image_text" placeholder="Say something about this image..."></textarea> </div> <div> <button type="submit" name="upload">POST</button> </div> </form> </div> </body> </html> 
  • $target = "images/"."image_upload($image)"; what's in the images directory? Do you have a file called image_upload($image) ? if so then you refer to just $ image. If not, this function should be $target = "images/".image_upload($image); - Ruslan Semenov
  • thanks for the answer. just now, second by second, $ target = "images /"."$ image"; so put and went ... only you do not know why, after updating the page, the records are copied and displayed again? type added record - updated and it appears for the second time ... - Sasuke Uchiha
  • To begin, the variable does not need to be wrapped in quotes. And so on f5, these forms are sent again, so you need to make the transition after loading and not continue the script. - Ruslan Semenov
  • I understood, thanks more ... I do not know if there is a "best answer" button here or not ... I just registered here. - Sasuke Uchiha
  • In this correspondence there is no, only the up arrow is there, but you may not. And so if they write a full-fledged answer, then a check mark appears on the question. Good luck. - Ruslan Semenov

0