ngreenwood6 Posted August 1, 2008 Share Posted August 1, 2008 I have this code: if (!$_email) { echo ("You are missing some information!"); } elseif (!$lastname) { echo ("You are missing some information!"); } elseif (!$firstname) { echo ("You are missing some information!"); } They all have the same output as you can tell "you are missing some information". I want it to make sure that they enter their firstname, last name and password. If they dont to display "you are missing some information." is there a simpler way to do this. sorry i am a total noob. I am looking for something like (!$firstname) and (!$lastname) and (!$email). Quote Link to comment https://forums.phpfreaks.com/topic/117660-solved-quick-question/ Share on other sites More sharing options...
ainoy31 Posted August 1, 2008 Share Posted August 1, 2008 All three conditions must to be met otherwise display the error message? If so, I would do this: if(emty($email) && empty($lastname) && empty($firstname)) { echo "You are missing some information!"; } else { echo ....etc } Is this what you are looking for? Quote Link to comment https://forums.phpfreaks.com/topic/117660-solved-quick-question/#findComment-605199 Share on other sites More sharing options...
DarkWater Posted August 1, 2008 Share Posted August 1, 2008 I'd use || (or) not && (and). Quote Link to comment https://forums.phpfreaks.com/topic/117660-solved-quick-question/#findComment-605200 Share on other sites More sharing options...
ngreenwood6 Posted August 1, 2008 Author Share Posted August 1, 2008 If i am correct the (!$email) by adding the "!" it means that nothing was set to $email. Is that not the right way to do things? Should I use the empty($email) type? What is the best method? I am new to php and am trying to get the best methods down while I am a beginner so that I do not get into bad habits or use false coding. Quote Link to comment https://forums.phpfreaks.com/topic/117660-solved-quick-question/#findComment-605205 Share on other sites More sharing options...
Andy-H Posted August 1, 2008 Share Posted August 1, 2008 I use empty() on everything but the $_POST['submit'] never seems to work for some reason. Also if data is going into a database use mysql_real_escape_string() or md5() for password encryption. If it's going to be displayed use htmlspecialchars(). Quote Link to comment https://forums.phpfreaks.com/topic/117660-solved-quick-question/#findComment-605207 Share on other sites More sharing options...
Andy-H Posted August 1, 2008 Share Posted August 1, 2008 DarkWater taught me most of that lol Ty xD Quote Link to comment https://forums.phpfreaks.com/topic/117660-solved-quick-question/#findComment-605210 Share on other sites More sharing options...
DarkWater Posted August 1, 2008 Share Posted August 1, 2008 Aha, lol. Yeah, those are pretty good rules to follow in general. Use htmlspecialchars on any HTML to be displayed so it doesn't allow HTML to actually be displayed. =P Also, the nl2br() function comes in handy. Quote Link to comment https://forums.phpfreaks.com/topic/117660-solved-quick-question/#findComment-605211 Share on other sites More sharing options...
ngreenwood6 Posted August 1, 2008 Author Share Posted August 1, 2008 Thanks for the help and info guys. It's nice to have a community and people in the community that is willing to help people (especially noobs) lol. Quote Link to comment https://forums.phpfreaks.com/topic/117660-solved-quick-question/#findComment-605212 Share on other sites More sharing options...
ainoy31 Posted August 1, 2008 Share Posted August 1, 2008 i use empty() because of the following things are considered to be empty: "" (an empty string) 0 (0 as an integer) "0" (0 as a string) NULL FALSE array() (an empty array) var $var; (a variable declared, but without a value in a class) and Darkwater was right about using || instead of &&. I got switched on my logic there. You would want at least one of the conditions to be true and using || allows that. the &&, all three conditions must be met, otherwise your message will not be displayed. Quote Link to comment https://forums.phpfreaks.com/topic/117660-solved-quick-question/#findComment-605213 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.