Jump to content

Recommended Posts

I got two links with a parameter with a value. When I click either link it will send me to the same challenge.php page, I'm wanting to find the value of the parameter and display the page according to what value the parameter has in the url.

This script doesn't seem to be working.

<a href="http://www.site.com/challenge.php?id=1">Complete Challenge 1</a>
<a href="http://www.site.com/challenge.php?id=2">Complete Challenge 2</a>

$id = $_GET['id'];
if ($id=1) {
        echo "This is challenge 1 completed";
} elseif ($id=2) {
echo "This is challenge 2 completed";
else {
echo "The URL parameters didn't work";
}

Any help would be appreciated thanks.

Link to comment
https://forums.phpfreaks.com/topic/256226-_get-and-url-parameters/
Share on other sites

When comparing two values, use the comparison operator == not the assignment operator =. Your code should looks like this.

 

$id = (int)$_GET['id'];
if ($id == 1) {
        echo "This is challenge 1 completed";
} elseif ($id == 2) {
echo "This is challenge 2 completed";
else {
echo "The URL parameters didn't work";
}

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.