My program needs to upload images, so an image (varchar) location is saved in a MySQL database. It's working so far.
Now I want to display images and this does not work. Here is the code:
include ('connect.php');
if(isset($_POST['submit'])){
$filetemp= $_FILES['image'] ['tmp_name'];
$filename= $_FILES['image'] ['name'];
$filepath= "images/".$filename;
move_uploaded_file($filetemp,$filepath);
$sql=mysqli_query($con,"insert into images (image) value ('$filepath')");
if($sql){
echo "uploaded";
}
else{
echo " not uploaded";
}
}
$sql=mysqli_query($con,"select * from images");
while($row=mysqli_fetch_array($sql)){
echo "<img src=' images/".$row['image']."'>"; // the problem is here, its just displaying img icon, not actual image
}
?>
imagein the db? also, the path in theimgtag has a leading space before ` images/`INSERTquery is highly vulnerable for SQL injection - have a look at prepared statements to avoid getting hacked