passing php variables into href - need syntax help

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
kingfisher2011
Forum Newbie
Posts: 1
Joined: Sun Nov 06, 2011 9:58 am

passing php variables into href - need syntax help

Post by kingfisher2011 »

Hi,
I have been trying to pass a php variable into `a href`. I am by no means a pro, have looked up as many sites as possible to get the right syntax but just cant seem to get it right. Hope someone can help me. Here is the sample code I am trying to fix.

<input name="paymentform" class="butstyle" type="button" value="Click" onclick="location.href='pay2.htm?orderid='<?php echo $_SESSION['randno'] ?>'"/>

Seems fairly straight forward but just cant seem to get it right. $_SESSION['randno'] needs to be passed into this url so that the next page, pay2.html can pick it up.

Help please?
internet-solution
Forum Contributor
Posts: 220
Joined: Thu May 27, 2010 6:27 am
Location: UK

Re: passing php variables into href - need syntax help

Post by internet-solution »

You have unmatched quotes. You do not need the single (') quote after orderid=

If you want to keep it, then you will have to escape it and add a matching escaped quote on the other side.
Post Reply