Jump to content

[SOLVED] Quick question


ngreenwood6

Recommended Posts

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).

Link to comment
https://forums.phpfreaks.com/topic/117660-solved-quick-question/
Share on other sites

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?

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.

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().

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.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.