Joefunkx Posted June 19, 2007 Share Posted June 19, 2007 Hey guys, here's my problem- I am calling a page with a parameter and I want to be able to condition code on that page depending on the parameter. The link i use is this- <A HREF="test.php?agent=test"> the test.php file consists of the following- <?php echo $_GET['agent']; if ($agent="blah") { echo "Have a nice weekend!"; } ?> the output on that page is- test Have a nice weekend! As you can see, it shouldn't be outputting the "Have a nice weekend!" statement as the agent parameter is "test", not "blah". Any help with this would be appreciated Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/56230-solved-need-help-with-parameter/ Share on other sites More sharing options...
jvrothjr Posted June 19, 2007 Share Posted June 19, 2007 <?php echo $_GET['agent']; if ($agent == "blah") { echo "Have a nice weekend!"; } ?> [\code] Quote Link to comment https://forums.phpfreaks.com/topic/56230-solved-need-help-with-parameter/#findComment-277717 Share on other sites More sharing options...
akitchin Posted June 19, 2007 Share Posted June 19, 2007 in case it's not obvious, jvrothjr added an extra equal sign to your if() condition. you were using one, which is simply an assignment, which will always evaluate to true. you should also be using $_GET['agent'] in the if(). Quote Link to comment https://forums.phpfreaks.com/topic/56230-solved-need-help-with-parameter/#findComment-277721 Share on other sites More sharing options...
Joefunkx Posted June 19, 2007 Author Share Posted June 19, 2007 I tried that code.. It doesn't display the "Have a nice weekend!" at all, which is good because "blah" isn't the value of AGENT. However, when i change code to $agent == "test", it still doesn't display "Have a nice weekend!" even though the condition is true. Quote Link to comment https://forums.phpfreaks.com/topic/56230-solved-need-help-with-parameter/#findComment-277728 Share on other sites More sharing options...
jvrothjr Posted June 19, 2007 Share Posted June 19, 2007 <?php $agent = $_GET['agent']; if ($agent == "blah") {echo "Have a nice weekend!";} ?> OR As akitchin stated <?php if ($_GET['agent'] == "blah") {echo "Have a nice weekend!";} ?> Quote Link to comment https://forums.phpfreaks.com/topic/56230-solved-need-help-with-parameter/#findComment-277735 Share on other sites More sharing options...
Joefunkx Posted June 19, 2007 Author Share Posted June 19, 2007 Nice, that works I'm an idiot. Thanks guys Quote Link to comment https://forums.phpfreaks.com/topic/56230-solved-need-help-with-parameter/#findComment-277739 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.