phpmysqlimagebroken-image

how to fetch my image from my database where my upload path folder?


i already look in stackoverflow where i have a similar problem. but it wont just work on me.

Is it possible that the problem is how i upload my image into the folder? this is the common answer in the stackoverflow and they say it work but it wont work on me the image will still display broken.

Ps. im sorry if the problem is not specify enough. this my first asking here in stackoverflow

this is just an example to what i have:

<?php
include('session.php');

$query = mysqli_query($link, "SELECT * from tbl_menu");
while($res = mysqli_fetch_array($query)){

 echo "<img src='Image_name/".$res['image']."'>";
}
?>

this is how i upload my image:

<?php
include_once('connect.php');

if(isset($_POST['AddMenu'])){

$uploadimage = 'C:/xampp/htdocs/thesis/Images_name/'.$_FILES["image"]["name"];

    $mname =$_POST['mname'];
    $price =$_POST['price'];
    $mcategory =$_POST['mcategory'];
    $image =$_FILES['image']['name'];


mysqli_query($link, "INSERT into tbl_menu(mname, price, mcategory, image) values('$mname', '$price', '$mcategory', '$image')");


if (move_uploaded_file($_FILES["image"]["tmp_name"], $uploadimage)) {
    $msg = "image upload";
}else {
    $msg = "not upload";
}
header("location: menu.php");
}
?>

Solution

  • 
     echo "<img src='http://localhost/thesis/Image_name/".$res['image']."'>";
    
    

    I would recommend you save a variable "home" as "http://localhost/thesis/" in your main config file. and use that variable where ever you need.