Copy link to clipboard
Copied
I have an image with some underlying PHP which, when clicked, causes it to link to another page and pass a parameter, this works fine when the image is on it's own in a table cell see www.hollisterairshow.com/admin/admin.php and then select the "Needs with Offers" tab and you'll see the icon on the right which takes the user to a page to update the Offer. The working code is shown below:
<td>
<a href="editoffer.php?offerId=<?php echo $row_rsNeedsOffers['offerId']; ?>">
<img src="../images/edit.png" alt="Edit Offer" width="24" height="24" border="0" align="middle" Title = "Edit Offer"/></a>
</td>
I didn't like the look of the page so I improved it....sigh...and now it doesn't work ! The offending page can be seen here www.hollisterairshow.com/admin/admin2.php and then select the "Needs with Offers" tab and you'll see the icon at the end of each offer. The parameter is not being evaluated and instead of correctly passing for example "http://www.hollisterairshow.com/admin/editoffer.php?offerId=18" it passes "http://www.hollisterairshow.com/admin/editoffer.php?offerId=<?php echo $row_rsNeedsOffers['offerId']; ?>" . As you can see the parameter is not being evaluated and the PHP is being passed as a parameter. I tried removing the <?PHP and ?> and this failed. The relevant code is shown in red below
<?php do { ?>
<p>
<?php
echo "<b>".$row_rsNeedsOffers['title']."("."</b>".$row_rsNeedsOffers['quantityneeded']." needed)"."<br />".$row_rsNeedsOffers['name']."(".$row_rsNeedsOffers['quantityoffered']." available) ".$row_rsNeedsOffers['commentoffered']." E-mail: ".$row_rsNeedsOffers['email']." Phone: ".$row_rsNeedsOffers['phone']." Admin comment: ".$row_rsNeedsOffers['admincomment']." Status: ".$row_rsNeedsOffers['status']." "."<a href=\"editoffer.php?offerId=<?php echo \$row_rsNeedsOffers['offerId']; ?>\"><img src=\"../images/edit.png\" alt=\"Edit Offer\" width=\"16\" height=\"16\" border=\"0\" align=\"middle\" Title = \"Edit Offer\"/></a>";
?>
</p>
<?php } while ($row_rsNeedsOffers = mysql_fetch_assoc($rsNeedsOffers)); ?>
I must have made a syntax error somewhere, but I just don't see it.
Thanks,
Tony
You cannot nest one PHP code block inside another. The error is here:
<a href=\"editoffer.php?offerId=<?php echo \$row_rsNeedsOffers['offerId']; ?>\">
It should be this:
<a href=\"editoffer.php?offerId={$row_rsNeedsOffers['offerId']}\">
The curly braces are necessary in order to embed an associative array element in a string. See the section on Complex (curly) syntax on the following page of the PHP Manual: http://docs.php.net/manual/en/language.types.string.php#language.types.string.parsing.
Althoug
...Copy link to clipboard
Copied
You cannot nest one PHP code block inside another. The error is here:
<a href=\"editoffer.php?offerId=<?php echo \$row_rsNeedsOffers['offerId']; ?>\">
It should be this:
<a href=\"editoffer.php?offerId={$row_rsNeedsOffers['offerId']}\">
The curly braces are necessary in order to embed an associative array element in a string. See the section on Complex (curly) syntax on the following page of the PHP Manual: http://docs.php.net/manual/en/language.types.string.php#language.types.string.parsing.
Although that will fix your error, the reason you found it so difficult to find the syntax error is because of the cumbersome way you have used echo for all your HTML. It would be much easier to maintain if you rewrote the same code like this:
<?php do { ?>
<p><b><?php echo $row_rsNeedsOffers['title']; ?>(</b><?php echo $row_rsNeedsOffers['quantityneeded']; ?> needed).<br />
<?php echo $row_rsNeedsOffers['name']; ?>(<?php echo $row_rsNeedsOffers['quantityoffered']; ?>. available)
<?php echo $row_rsNeedsOffers['commentoffered']; ?>
E-mail: <?php echo $row_rsNeedsOffers['email']; ?>
Phone: <?php echo $row_rsNeedsOffers['phone'];?>
Admin comment: <?php $row_rsNeedsOffers['admincomment']; ?>
Status: <?php echo $row_rsNeedsOffers['status']; ?>
<a href="editoffer.php?offerId=<?php echo $row_rsNeedsOffers['offerId']; ?>">
<img src="../images/edit.png" alt="Edit Offer" width="16" height="16" border="0" align="middle" title="Edit Offer"/></a>
</p>
<?php } while ($row_rsNeedsOffers = mysql_fetch_assoc($rsNeedsOffers)); ?>
PHP is designed to be embedded in HTML, so there's nothing wrong in switching in and out of PHP code multiple times. It makes your code easier to read and maintain, particularly with the help of Dreamweaver's syntax colouring. It also avoids the mess of backslashes to escape quotes.
Copy link to clipboard
Copied
Perfect, that worked. Thank you so much and thanks for the advice on structuring my code to be more readab
le, much appreciated.
Tony
Find more inspiration, events, and resources on the new Adobe Community
Explore Now