-1

I have a image path stored the the database under location upload/imagename.png but I cant get it display on my page any help?

The images are stored in a image folder and in the database like image/name.png but can I take the path from the db and display it?

I have error reporting on but still nothing just a blank page.

<?php include_once('dbconnect.php'); ?>

<?php error_reporting(E_ALL);
ini_set('display_errors', 1); ?>

<?php

if(!empty($_GET['id'])){
    //Get image path from database
    $result = $con->query("SELECT id, location FROM images WHERE id = {$_GET['id']} AND location = {$_GET['location']}");

    if($result->num_rows > 0){
        $imgData = $result->fetch_assoc();

echo '<img src='".$row['location']."' />';
    }else{
        echo 'Image not found...';
    }
}
?>

You access the page like http://yoursite.com/recent.php?id=xxx

EDIT: I tried this

<?php include_once('dbconnect.php'); ?>

<?php error_reporting(E_ALL);
ini_set('display_errors', 1); ?>

<?php

if(!empty($_GET['id'])){
    //Get image data from database
    $result = $con->query("SELECT id, location FROM images WHERE id = {$_GET['id']} AND location = {$_GET['location']}");

    if($result->num_rows > 0){
       while($imgData = $result->fetch_assoc()){
           echo '<img src="'.$imgData['location'].'"/>';
       }
   }else{
        echo 'Image not found...';
   }
}
?>

Now I get

Notice: Undefined index: location in /home/vol15_4/epizy.com/epiz_20687250/yourwebprojects.22web.org/htdocs/3/recent.php on line 10

Notice: Trying to get property of non-object in /home/vol15_4/epizy.com/epiz_20687250/yourwebprojects.22web.org/htdocs/3/recent.php on line 12

1 Answers1

0

You are certainly getting an undefined error for $row:

 if($result->num_rows > 0){
       while($imgData = $result->fetch_assoc()){
           echo '<img src="'.$imgData['location'].'"/>';
       }
   }else{
        echo 'Image not found...';
   }
Kisaragi
  • 2,198
  • 3
  • 16
  • 28
  • So I updated the code with the one above now I get Notice: Undefined index: location in /home/vol15_4/epizy.com/epiz_20687250/yourwebprojects.22web.org/htdocs/3/recent.php on line 10 Notice: Trying to get property of non-object in /home/vol15_4/epizy.com/epiz_20687250/yourwebprojects.22web.org/htdocs/3/recent.php on line 12 – VideoGameSongGuy Oct 26 '17 at 20:30
  • `var_dump($imgData)` and start from there – Kisaragi Oct 26 '17 at 20:33
  • I edited the post with the new code when I got the errors if you would like to take a look that will be nice. – VideoGameSongGuy Oct 26 '17 at 20:35
  • I seem to cant fix. Any suggestions / help? – VideoGameSongGuy Oct 26 '17 at 23:27