1

Below is my code for display information of an image including its file, but this is not displaying, I don't know why.

 <?php
      include('config/dbconnect.php');  
      if(isset($_GET['id'])) 
      { 
            $id = $_GET['id'];
            $sql = mysqli_query($con, "SELECT * FROM collage WHERE id = '$id'");
            while($row = mysqli_fetch_array($sql)) {
                  $name = $row['name'];
                  $content = $row['content'];
                  $size = $row['size'];
                  $type = $row['type'];
                  $date_upload = $row['date_upload'];
                  $file = $row['file'];
            }
      }
?>
<div class='body-content'>
<div class='img-name-cont'><h3><?php echo $name; ?></h3></div>
<div class='img-detail-cont'>upload: <?php echo $date_upload; ?><br>type: <?php echo $type; ?><br>size: <?php echo $size; ?>KB </div>
<div class='img-file-cont'>
<img src="img/collage/<?php echo $row['file'] ?>" style="width:130px; height:100%"></div>
<div class='img-content-cont'><?php echo $content; ?></div>
</div>
7
  • view page source -- is the HTML correct? Commented Jul 8, 2016 at 4:01
  • do you get any error code in code inspector?? PS: your code can be injected by sql injection Commented Jul 8, 2016 at 4:07
  • After <?php add error_reporting(E_ALL);ini_set('display_errors',1); And write $sql = mysqli_query($con, "SELECT * FROM collage WHERE id = '$id'") or die (mysqli_error($con)); and check for errors Commented Jul 8, 2016 at 4:20
  • 1
    missing ; at `<?php echo $row['file'] ?>' Commented Jul 8, 2016 at 4:46
  • check the given path name is correct Commented Jul 8, 2016 at 4:50

5 Answers 5

2

First of all use inspect to check whether the image is actually pointed to by the code. that is the actual loation might not be pointed at. what is your folder structure.

" style="width:130px; height:100%">

your code is ok. as long as php echo $row['file'] returns a file

Sign up to request clarification or add additional context in comments.

Comments

1

The problem here is "Your all the variables are local to the while loop". so you can't access it outside of the while loop. Try this code.

 <?php
      include('config/dbconnect.php');  
      if(isset($_GET['id'])) 
      { 
            $id = $_GET['id'];
            $sql = mysqli_query($con, "SELECT * FROM collage WHERE id = '$id'");
            while($row = mysqli_fetch_array($sql)) {
        ?> 

                  <div class='body-content'>
                  <div class='img-name-cont'><h3><?php echo $row['name']; ?></h3></div>
                  <div class='img-detail-cont'>upload: <?php echo $row['date_upload']; ?><br>type: 
                  <?php echo $row['type']; ?><br>size: <?php echo $row['size']; ?>KB </div>
                  <div class='img-file-cont'>
                  <img src="img/collage/<?php echo $row['file']; ?>" style="width:130px; height:100%"></div>
                  <div class='img-content-cont'><?php echo $row['content']; ?></div>
                  </div>
        <?php
            }
      }
?>

Comments

0

Be sure to check echo $row['file'] if it returns the correct string of your image path with the correct file extension .

Comments

0

try this one :

first of all you have to check if your image path ok or not using this php function:

<?php $img=getimagesize($imagewithpath); if($img=="") { echo "there is no image ";} else{ ?> <img src="<?php echo $imagewithpath; ?>" style="width:130px; height:100%"> <?php } ?>

Comments

0

As answered by Dulaj Sanjaya all your variables are local so you can't use that outside of while.

Second if you want to use your code then you have taken all data of $row in different variables then used outside of file then why don't you used same $file for image why you have used $row['file']?

Simply replace this line as

<div class='img-file-cont'>
                  <img src="img/collage/<?php echo $file; ?>" style="width:130px; height:100%"></div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.