problem with showimage.php?image

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ximm
Forum Newbie
Posts: 2
Joined: Fri Oct 17, 2003 4:04 am

problem with showimage.php?image

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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>
ximm
Forum Newbie
Posts: 2
Joined: Fri Oct 17, 2003 4:04 am

it doesn't work

Post 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.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

you need to show the code in showimage.php

Mark
RFairey
Forum Commoner
Posts: 52
Joined: Fri Jun 06, 2003 5:23 pm

Post 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

Code: Select all

<?php
$image = $_GET['image'];
?>
To read in the value of image from the URL (assuming register globals is off).
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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>&nbsp;</td>
    <td>
        <a href="page_to_link_to.php">
            <img src="showimage.php?image=photo1.jpg" alt="" title="" />
       </a>
    </td>
</tr>
</table>
END;
Mac
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

Hey! heredoc, that's my line! :P

Well said from Mac :D, click the last link in my signature if you want to learn more about heredoc.

-Nay
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post 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 :wink: :)
Post Reply