daebat Posted April 13, 2009 Share Posted April 13, 2009 I am working on a website in which the person wants a person to look at a list of instructors click on a link below the instructor that would take you to a page with a printable coupon and dynamically list the instructors name on the coupon. In essence this would require me to only have one page designed for the coupon and if I add users it should pop up. I know that this has something to do with a call to a stored variable but I don't know php very well so thanks for any help! Quote Link to comment https://forums.phpfreaks.com/topic/153885-wordpress-question/ Share on other sites More sharing options...
gizmola Posted April 14, 2009 Share Posted April 14, 2009 Honestly, I don't even know where to begin. About all I can say is that PHP scripts can access URL params from the $_GET superglobal variable. So if the main page had something like: Discount Coupon for Bob Jones then in coupon.php you can get access to the name variable using: //probably should be in an include -- define your list of OK people, could use to emit the original list $instructors = array(); $instructors['bobjones'] = array('fname' => 'Bob', 'lname' => 'Jones', 'Discount' => '5'}; $instructors['fredsmith'] = array('fname' => 'Fred', 'lname' => 'Smith', 'Discount' => '10'}; //etc. $name = $_GET['name']; if (array_key_exists($name, $instructors) { // Ok found the person echo "Here's your coupon for {$instructors[$name]['fname']} {$instructors[$name]['lname']}. "; echo "Discount {$instructors[$name]['Discount']}%. "; echo "Good until xyz Date."; } else { // Hacking the url? echo 'Sorry, couldn't find a valid coupon.'; } Quote Link to comment https://forums.phpfreaks.com/topic/153885-wordpress-question/#findComment-809375 Share on other sites More sharing options...
daebat Posted April 14, 2009 Author Share Posted April 14, 2009 <?php $instructors = array(); $instructors['terrykennedy'] = array('fname' => 'Terry', 'lname' => 'Kennedy', 'Discount' => '5'); $name = $_GET['name']; if (array_key_exists($name, $instructors) { echo "Here is your coupon for {$instructors[$name]['fname']}{instructors[$name]['lname']}. <br />"; echo "Discount {$instructors[$name]['Discount']}%. <br />"; echo "Good until xyz Date."; } else { echo 'Sorry, couldn't find a valid coupon.'; } ?> This gives me: Parse error: syntax error, unexpected '{' in /home/balancew/public_html/bwcoachinvite.php on line 9 I'm a noob when it comes to php. How should I do the include / define my list of people? Thanks gizmola! Quote Link to comment https://forums.phpfreaks.com/topic/153885-wordpress-question/#findComment-809643 Share on other sites More sharing options...
daebat Posted April 14, 2009 Author Share Posted April 14, 2009 Ok I figured out that I wasn't closing the if statement and changed out single quotes for double quotes on the bottom echo statement. Now I'm just getting a "sorry couldn't find a valid coupon..." i'm guessing that this is because I didn't do an include and define the variables. let me know what you think. I don't know how to define. Quote Link to comment https://forums.phpfreaks.com/topic/153885-wordpress-question/#findComment-809663 Share on other sites More sharing options...
daebat Posted April 14, 2009 Author Share Posted April 14, 2009 I got it to work with the following code: <?php $instructors = array(); $instructors['terrykennedy'] = array('fname' => 'Terry', 'lname' => 'Kennedy'); $instructors['chadpolstra'] = array('fname' => 'Terry', 'lname' => 'Kennedy'); $name = $_GET['name']; if (array_key_exists($name, $instructors)) { echo "Here is your coupon for {$instructors[$name]['fname']} {$instructors[$name]['lname']}. <br />"; } else { echo "Sorry, couldn't find a valid coupon."; } ?> with the following link http://www.balancewalking.com/bwcoachinvite.php?name=terrykennedy Quote Link to comment https://forums.phpfreaks.com/topic/153885-wordpress-question/#findComment-809751 Share on other sites More sharing options...
daebat Posted April 14, 2009 Author Share Posted April 14, 2009 So now what I am wondering is if there is a way to set this up without having to edit the php every time I add a person... is there a way to simply add a name after http://www.balancewalking.com/bwcoachinvite.php?name= and have it display? the code I have up to this point is as follows: <html> <body> <img src="http://footsolutions.com/files/bw-coach_invite.png"> <div style="margin-left:175px; margin-top:-450px; font-size:300%;"> <?php $instructors = array(); $instructors['terrykennedy'] = array('fname' => 'Terry', 'lname' => 'Kennedy'); $instructors['chadpolstra'] = array('fname' => 'Chad', 'lname' => 'Polstra'); $name = $_GET['name']; if (array_key_exists($name, $instructors)) { echo "{$instructors[$name]['fname']} {$instructors[$name]['lname']}<br />"; } else { echo "Sorry, couldn't find a valid coupon."; } ?> <!-- echo "<img src=http://footsolutions.com/files/bw-coach_invite.png>"; --> </div> </body> </html> See http://www.balancewalking.com/bwcoachinvite.php?name=terrykennedy for a working example of what I need. Quote Link to comment https://forums.phpfreaks.com/topic/153885-wordpress-question/#findComment-809847 Share on other sites More sharing options...
daebat Posted April 14, 2009 Author Share Posted April 14, 2009 SOLVED!!!!!!!!!!!!! <html> <body> <img src="http://footsolutions.com/files/bw-coach_invite.png"> <div style="margin-left:160px; margin-top:-450px; font-size:300%;"> <?php $name = $_GET['name']; echo "{$name}<br />"; ?> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/153885-wordpress-question/#findComment-810040 Share on other sites More sharing options...
gizmola Posted April 15, 2009 Share Posted April 15, 2009 The reason I gave you the code was to prevent tampering. Certainly you could send any name, but then I could go ahead and tamper with the url like this: http://www.balancewalking.com/bwcoachinvite.php?name=adolfhitler Also, obviously it is just showing the name garbled together, which isn't really what I was trying to illustrate. Of course if that works for you, far be it from me to complicate things, however the array gives you a way of setting up the list of people to feed the links. One of the common ways to maintain something like that would be to have the names in a table, which you can update using phpMyAdmin, or a flatfile. There's many different ways to handle it. Quote Link to comment https://forums.phpfreaks.com/topic/153885-wordpress-question/#findComment-810335 Share on other sites More sharing options...
Aaron111 Posted April 18, 2009 Share Posted April 18, 2009 I am working on a website in which the person wants a person to look at a list of instructors click on a link below the instructor that would take you to a page with a printable coupon and dynamically list the instructors name on the coupon. In essence this would require me to only have one page designed for the coupon and if I add users it should pop up. I know that this has something to do with a call to a stored variable but I don't know php very well so thanks for any help! I HAVE A SIMULAR PROBLEM ALTHOGH IT MIGHT BE OFF TOPIC ..... can anyone let me know if and where on the server can I edite the main meta data tags please lol Quote Link to comment https://forums.phpfreaks.com/topic/153885-wordpress-question/#findComment-813007 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.