cheesybiscuits Posted February 2, 2012 Share Posted February 2, 2012 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 More sharing options...
scootstah Posted February 2, 2012 Share Posted February 2, 2012 A single equals is an assignment operator. You need two equals ( == ) in your if/elseif statement. Link to comment https://forums.phpfreaks.com/topic/256226-_get-and-url-parameters/#findComment-1313564 Share on other sites More sharing options...
AyKay47 Posted February 2, 2012 Share Posted February 2, 2012 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"; } Link to comment https://forums.phpfreaks.com/topic/256226-_get-and-url-parameters/#findComment-1313565 Share on other sites More sharing options...
cheesybiscuits Posted February 2, 2012 Author Share Posted February 2, 2012 Thanks! Keep getting them mixed up Link to comment https://forums.phpfreaks.com/topic/256226-_get-and-url-parameters/#findComment-1313568 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.