m4n1ac Posted February 20, 2013 Share Posted February 20, 2013 (edited) $error = $_GET['error']; if ($error===1) { echo"value is 1"; } the URL i've entered is http://localhost/index.php?error=1 why is this not working ? Edited February 20, 2013 by m4n1ac Quote Link to comment https://forums.phpfreaks.com/topic/274725-help-with-passing-variables-though-url/ Share on other sites More sharing options...
gristoi Posted February 20, 2013 Share Posted February 20, 2013 $error = $_GET['error']; if ($error==1) { echo"value is 1"; } Quote Link to comment https://forums.phpfreaks.com/topic/274725-help-with-passing-variables-though-url/#findComment-1413624 Share on other sites More sharing options...
AyKay47 Posted February 20, 2013 Share Posted February 20, 2013 $_GET and $_POST values are stored as strings so you cannot perform a strict comparison using a string and an integer, it will always equate to false. You can either use the loose comparison operator as Gristoi has done above, or you can cast the value stored in $_GET['error'] as an integer and use the strict comparison as you have done. As a side note, always check that $_GET and $_POST values isset before assigning their value to a variable. Quote Link to comment https://forums.phpfreaks.com/topic/274725-help-with-passing-variables-though-url/#findComment-1413627 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.