Page 1 of 1
problem with showimage.php?image
Posted: Fri Oct 17, 2003 4:04 am
by ximm
Hello, the code in my test page is :
**********************
<?php
echo "<table border=1>";
echo "<tr>";
echo "<td>";
echo "</td>";
echo "<td>";
echo "<A HREF='showimage.php?image="photo1.jpg"'>"; // line 17
echo "</A></td>";
echo "</tr>";
echo "</table>";
?>
*********************
But whe I try to display this file in a browser, it answers with the following error:
Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /home/public_html/test.php on line 17
Thank you in advance.
Posted: Fri Oct 17, 2003 4:27 am
by volka
check the colors the syntxhilighter assigns to your code
Code: Select all
<?php
echo "<table border=1>";
echo "<tr>";
echo "<td>";
echo "</td>";
echo "<td>";
echo "<A HREF='showimage.php?image="photo1.jpg"'>"; // line 17
echo "</A></td>";
echo "</tr>";
echo "</table>";
?>
if you start your string literal with " you must escape all "s within the literal or php
thinks it ends there (how should it know it does not?)
Code: Select all
<?php
echo "escape all "s within the literal. ' can be used freely in here";
echo 'escape all ''s within the literal. " can be used freely in here';
?>
In your code block there's nothing really to do for php, it only prints static strings. You can leave and re-enter php-blocks (almost) as you like. Anything outside a php-block will be sent as-is to the client, e.g.
Code: Select all
<html>
<head>
<title>jump in and out php-blocks test</test>
</head>
<body>
<?php if (isset($_POST['text'])) { ?>
<fieldset><legend>you've typed</legend>
<pre><?php print_r($_POST['text']); ?></pre>
</fieldset>
<?php } ?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>"
<textarea name="text"></textarea>
<input type="submit" />
</form>
</body>
</html>
it doesn't work
Posted: Wed Oct 22, 2003 10:06 am
by ximm
Thankyou for your response,
I have tested this:
echo "<A HREF='showimage.php?image=\"photo1.jpg\"'>";
but still it doesn't work. The browser doesn't give to me an error, but it doesn't show the image.
What I'm triying to do is an image galery.
Posted: Wed Oct 22, 2003 10:13 am
by JayBird
you need to show the code in showimage.php
Mark
Posted: Wed Oct 22, 2003 10:28 am
by RFairey
You're using single quotes around the HREF string - is that valid HTML? Plus the get variable need not have quotes at all.
I'd try:
Code: Select all
<?php
echo "<A HREF="showimage.php?image=photo1.jpg">";
?>
Then in showimage.php you need
To read in the value of image from the URL (assuming register globals is off).
Posted: Wed Oct 22, 2003 10:50 am
by twigletmac
To save having to escape double quotes you could have:
Code: Select all
echo '<a href="showimage.php?image=photo1.jpg">';
Although I'm not sure how the image will display if you have it within anchor tags, it should really be within image tags shouldn't it?
i.e. using heredoc format (another choice you have, although you may wish to break out of PHP and return to it once the HTML is done):
Code: Select all
echo <<<END
<table border="1">
<tr>
<td> </td>
<td>
<a href="page_to_link_to.php">
<img src="showimage.php?image=photo1.jpg" alt="" title="" />
</a>
</td>
</tr>
</table>
END;
Mac
Posted: Wed Oct 22, 2003 10:54 am
by Nay
Hey! heredoc, that's my line!
Well said from Mac

, click the last link in my signature if you want to learn more about heredoc.
-Nay
Posted: Fri Oct 24, 2003 2:15 pm
by vigge89
i think that this have been mentioned before, but i'll post it anyway;
i would do something like this:
Code: Select all
<?php
//Start echo...
echo "<table border="1">
<tr>
<td>
</td>
<td>
<A HREF="showimage.php?image=photo1.jpg"'>
</A></td>
</tr>
</table>
"; //End echo...
?>
That works, at least on my localhost
