-2

My question is why doesn't the image appear on my php page, i have image url in database under 'imageurl'. I want to echo url to image src and this will show the picture from the folder. The error is Parse error: syntax error, unexpected '<' in .... on line 95. I will put the line 95 in the sample code too.

<html>
   <body>
      <?php while($row = mysql_fetch_assoc($query)): ?>
         <div class="NewsItem">
            <div>
              <h1><?php echo $row['txt']; ?></a> <br>
              <span>posted on <?php echo $row['added']; ?></span><span> by <?php echo $row['adder'];?></span>

             </div>
             <div class="imgdiv"><?php if(($row['imageurl'] == 'NULL') or ($row['imageurl']== '')){
                 //No images
             }
             else{
            Line 95----  <img src="<?php echo $row['imageurl'];?>" width='300' height='300'/>
             }

             ?></div>
             <br>
             <div>
             <form action="comment.php"method="post" name="addComment"><input type="text" placeholder="kommentaar" name="commenttext" maxlenght="100"><input type="submit" name="addComment" value="Lisa kommentaar">
             <input id="prodId3" name="prodId3" type="hidden" value="<?php echo $row['id']; ?>">
             </form>
             </div>
          </div>

      <?php 
      endwhile;
      ?>
M.Kesküll
  • 43
  • 10

3 Answers3

0

Need to maintain php tags open and close at line #95

So, Change your else part like this:

else{ ?>
      <img src="<?php echo $row['imageurl'];?>" width='300' height='300'/>
<?php    }
Himanshu Upadhyay
  • 6,558
  • 1
  • 20
  • 33
0

You forget about printing the result after your elseif clause. Moreover, you should use alternative syntax in PHP template, it will make things easier to read/maintain (You did it for while/endwhile).

<?php while($row = mysql_fetch_assoc($query)): ?>
 <div class="NewsItem">
    <div>
      <h1><?php echo $row['txt']; ?></a> <br>
      <span>posted on <?php echo $row['added']; ?></span><span> by <?php echo $row['adder'];?></span>

     </div>
     <div class="imgdiv">
    <?php if(($row['imageurl'] == 'NULL') or ($row['imageurl']== '')): ?>
        No image
    <?php else: ?>
        <img src="<?php echo $row['imageurl'];?>" width='300' height='300'/>
    <?php endif; ?>
    </div>
     <br>
     <div>
     <form action="comment.php"method="post" name="addComment"><input type="text" placeholder="kommentaar" name="commenttext" maxlenght="100"><input type="submit" name="addComment" value="Lisa kommentaar">
     <input id="prodId3" name="prodId3" type="hidden" value="<?php echo $row['id']; ?>">
     </form>
     </div>
  </div>

<?php endwhile; ?>
Oulalahakabu
  • 504
  • 3
  • 6
0

In your code there is missmatch of opening and closing php tag, also put full URL of image with site URL Try the following code

else{ ?>
      <img src="<?php echo "your site url".$row['imageurl'];?>" width='300' height='300'/>
<?php    }
Bhupendra Mistry
  • 598
  • 3
  • 11