Jump to content

Archived

This topic is now archived and is closed to further replies.

daebat

WordPress Question

Recommended Posts

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!

Share this post


Link to post
Share on other sites

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.';

}

Share this post


Link to post
Share on other sites
<?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!

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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  :)

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.