Hi guys,

I'm a complete newbie here on PHP Builder. I've been dabbling with php for a while and trying to fathom the language out...however, I'm running a script and keep getting the following error:

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/blackwid/public_html/development/dbupload/view.php on line 13

the line in question is:

 echo "<td><img src="post.php?imgid=".$rs[0]."" width=100 height=100></td></tr>n";

my code is:

<?  
include "comm.inc"; connectdb(); $sql = "SELECT imgid,imgtype FROM tblimage ORDER BY imgid"; $result = @mysql_query($sql) or die(mysql_error()); echo "<table border=1>n";
echo "<tr><th>imgid</th><th>imgtype</th><th>imgdata</th></tr>n";
while ($rs=mysql_fetch_array($result)) {
echo "<tr><td>".$rs[0]."</td>";
echo "<td>".$rs[1]."</td>";
echo "<td><img src="post.php?imgid=".$rs[0]."" width=100 height=100></td></tr>n";
};
querytable.php?database=blackwid_content&table=tblimage echo "</table>n";
?>

I've tried various combinations of double and single quotes, backslashes, etc of the course of the past couple of days...but still nothing!

Was wondering if anyone could help?

Its probably something really simple and staring straight at me!

Many thanks in advance

Mark

    The issue is that you start a string with double-quotes, then the src attribute is to be surrounded by double-quotes. The first double-quote of the src attribute closes the string, so PHP expects either a semi-colon to end the statement, or a comma or dot to concatenate the string with something (variable, constant, another string...).

    So to fix your code, there's two ways to do it:

    1.) Escape the inner dobule-quotes by prepending them with backslashes:

      echo "<td><img src=\"post.php?imgid=".$rs[0]."\" width=100 height=100></td></tr>n";  

    2.) Use single-quotes to delineate the string:

     echo '<td><img src="post.php?imgid=' . $rs[0] . '" width=100 height=100></td></tr>';

      You need to escape your quotes within strings.

      So...

      echo "<td><img src="post.php?imgid=".$rs[0]."" width=100 height=100></td>n"; 
      

      Should be:

      echo '<td>
            <img src="post.php?imgid=' . $rs[0] . '" width="100" height="100">
      </td>' . "n"; 
      
      // OR:
      
      echo "<td>
            <img src=\"post.php?imgid=" . $rs[0] . "\" width=\"100\" height=\"100\">
      </td>' . "n"; 
      
      

      LOL, you beat me to it, Brett. :-p

        Rodney, Brett,

        Cheers guys, that worked a treat, there was a line of code in my original post that shouldnt have been there - I was using it for comparison purposes. Its allworking fine.....apart from when I click the lnk to view the image, yes I get a table of information, but where the images should be, I get the dreaded little red 'x'.

        any thoughts?

        cheers

        mark

          @: Heh, I guess I'll just have to move slower next time 😉 😛

          That's a path issue most likely. Is post.php really in the same directory as this file? If not, then update the path, otherwise it's something else.

          Something else...
          Probably an issue in the image generation script you're using. Possibly could be anything in there. Try taking a known good ID and just going to post.php?imgid=1 and see if an image is output for you. If not, you should get something like "This image cannot be displayed because it has errors" or something. If that happens, then take away the header() that sets the content type to that of the image, and your error messages will be revealed (if display_errors is on). Otherwise, look in the error log for messages.

          Other than that, that's all I can guess at what it is.

            Brett,

            I've had a look around and couldnt find anything...however, I ran a script to display the contents of a database table in the browser and the 'image' came back as:

            GIF89aæþþþûûûºººx”§j£ÈøøøãããüüüñññÑÑÑåååmŠœóóó´´´ÅÅÅèèèw²ÊÊʧ§§³³³¸¸¸Azž¿¿¿ýýýÀÖäáááj£ÇežÃy²×Z“·Jƒ§{»···n§Ëm¦Ëêêêòòò±Í๹¹ÈÈÈìììÎÝæöööæææœ®d€“ÝÝÝ‚Ÿ±ÂÂÂvºh¨Ñùùùàààïïïx¼¹Ëw”¦t‘£ƒµÕ°·¼f‚••£õõõßßßúúú r»ÿÿÿ !ù , ¶€B‚ƒ„…†‡ˆ‰Š‚  ‹† )‘’Œ@:A7.5›BAA/'+›3%6©@›@2A1A-?¸’>A=A<›!;AÍÄA9&׋(A8àŠ $Aéä>ñó¤‚öøêÄ÷òü-âÞ&‚ùô!¨h¡Ab"‚°€aÀ•¾"XH0Â"© ÐxàC)S*|`Rߢ@

            I know something is very wrong with either the way my upload script is coded or the way in which the database table is set up (I'm guessing that it may be something to do with field types - its set to blob at the moment).

            baffled.....

            Mark

              4 days later

              Okay, so take that output, [man]base64encode/man that output, and then store that in the database. Then when you're ready to use it, just grab it from the DB, base64decode it and send the proper headers out and you're golden 😉

                Write a Reply...