m4n1ac Posted February 20, 2013 Share Posted February 20, 2013 $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 ? 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"; } 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. 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
Archived
This topic is now archived and is closed to further replies.