magnetica Posted March 2, 2007 Share Posted March 2, 2007 The code below simply checks if the variable $name is set and returns a string accordingly. But it works if the $name is set but if it is not then is doesn't? Why is this? Whats wrong with this? $name = $_POST['name']; if ( !isset($name) ) { echo "Not Set"; } else { echo $name; } Link to comment https://forums.phpfreaks.com/topic/40842-so-simple-isset/ Share on other sites More sharing options...
Orio Posted March 2, 2007 Share Posted March 2, 2007 It is always set... Because you set it to the value of $_POST['name'] (which can be set or not). This is what you meant: <?php if ( !isset($_POST['name']) ) { echo "Not Set"; } else { echo $_POST['name']; } ?> Orio. Link to comment https://forums.phpfreaks.com/topic/40842-so-simple-isset/#findComment-197750 Share on other sites More sharing options...
magnetica Posted March 2, 2007 Author Share Posted March 2, 2007 Oh of course.. Haha Just me not thinking logically again LOL Cheers Link to comment https://forums.phpfreaks.com/topic/40842-so-simple-isset/#findComment-197758 Share on other sites More sharing options...
magnetica Posted March 2, 2007 Author Share Posted March 2, 2007 That didn't work so I changed it to: if ( empty($_POST['name']) ) { echo "Not Set"; } else { echo $_POST['name']; } Link to comment https://forums.phpfreaks.com/topic/40842-so-simple-isset/#findComment-197763 Share on other sites More sharing options...
Orio Posted March 2, 2007 Share Posted March 2, 2007 That depends. I suppose you have a form that contains a text field named "name". By checking if it is not set, you are checking if the form was submitted or did someone access directly to the file processing the form. By checking if it is empty, you are checking if the form was submitted and someone didn't fill in the "name" field. Orio. Link to comment https://forums.phpfreaks.com/topic/40842-so-simple-isset/#findComment-197766 Share on other sites More sharing options...
magnetica Posted March 2, 2007 Author Share Posted March 2, 2007 Well yes. As i figured out checking with the isset is to check if the forms submitted no matter whether it is or isn't set it will always be true Link to comment https://forums.phpfreaks.com/topic/40842-so-simple-isset/#findComment-197800 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.