-2

I am having a problem in my query I am fetching data but the image tag is showing that there is a syntax problem .

> <?php
>     $query = "SELECT * from tbl_showrides";
>     $result = mysql_query($query);
>     while($row = mysql_fetch_array($result)){
>     $query_img = "SELECT image_name FROM tbl_rides_image WHERE
>     ride_id=".$row['id'].'  LIMIT 1';
>     $result_img = mysql_query($query_img);
>     $row_img = mysql_fetch_assoc($result_img);
>     <img src="<?php echo $base_url.'rides/'.$row_img['image_name']?>"/>
>     }
>     ?>
  • You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). – Quentin May 27 '13 at 17:52
  • If there is a `"` in your php output , it could upset the resulting HTML. Have you tried to view source and see in what way the image tag is not being set up correctly? Or is the error triggered by PHP itself? – EnKrypt May 27 '13 at 17:53
  • What error checker is showing this syntax error? What, specifically, does the error message say? Are you using an HTML syntax checker on PHP (if so, *that* is your problem, PHP is not HTML, use the right tool for the job). – Quentin May 27 '13 at 17:53
  • Parse error: parse error in D:\wamp\www\autodealers\ride.php on line 315 – user2032387 May 27 '13 at 17:55
  • What error checker is showing this syntax error? – Quentin May 27 '13 at 17:56

2 Answers2

2

This is because you placed <img> tag (which is html code) without closing the php tag. Simply change to :

 $row_img = mysql_fetch_assoc($result_img); ?>
 <img src="<?php echo $base_url.'rides/'.$row_img['image_name']?>"/>
 <?php }

I would also like to remind you that mysql_ functions are deprecated so it is advised that you switch to mysqli or PDO for new projects.

EnKrypt
  • 777
  • 8
  • 23
Fabio
  • 23,183
  • 12
  • 55
  • 64
0

You should not add php tag again inside the php tag..

<img src="<?php echo $base_url.'rides/'.$row_img['image_name']?>"/>

should be

$img = '<img src="'.$base_url.'rides/'.$row_img['image_name'].'"/>';
sAnS
  • 1,169
  • 1
  • 7
  • 10