Jump to content

IF and ORS (||)


Recommended Posts

This is the code I have:

if(!empty($name)) || (!empty($username)) || (!empty($password)) || (!empty($password2)) || (!empty($email)) || (!empty($email2)) || (!empty($gender)) || (!empty($security)) || (!empty($adminpw))


I know it's wrong because it's giving me this error:

Parse error: syntax error, unexpected T_BOOLEAN_OR in /home/tickets/public_html/register.php on line 41


But I searched everywhere on coding forums and guides and I can't... find the OR in an IF statement that works. I know it's that symbol, but I can't combine it with the !empty() function.


Already tried this as well:

if(!empty($name) || !empty($username) || !empty($password) || !empty($password2) || !empty($email) || !empty($email2) || !empty($gender) || !empty($security) || !empty($adminpw))

Link to comment
Share on other sites

I'm just going to take a stab in the dark here and say that what you want to do with the !empty() conditionals should use the boolean && instead.  If you used the way you had, your conditional would evaluate to TRUE as long as ANY of those fields were not empty.  It looks to me like a registration script of some kind, so the natural assumption is that you would only want the conditional to be TRUE as long as NONE of the fields were empty, in which case you would use && instead of ||.



Link to comment
Share on other sites

But NOW, it's not posting the form at ALL. It keeps saying that error message over and over again.

This is what I have:

if(!empty($name) && !empty($username) && !empty($password) && !empty($password2) && !empty($email) && !empty($email2) && !empty($gender) && !empty($security) && !empty($adminpw))

Link to comment
Share on other sites

39. if(isset($_POST['submit']))
40. {
41. 	if(!(empty($name) && empty($username) && empty($password) && empty($password2) && empty($email) && empty($email2) && empty($gender) && empty($security) && empty($adminpw)))
42. 	{
43. 		if($password == $password2)
44. 		{
45. 			if($email == $email2)
46. 			{


That is line 39 - 46.


There is no error message. But whenever I submit the form WHILE leaving $name blank, it still goes through and inserts it into the database leaving it blank D:


And then if I put line 41, like this:

41. if(!empty($name) && !empty($username) && !empty($password) && !empty($password2) && !empty($email) && !empty($email2) && !empty($gender) && !empty($security) && !empty($adminpw))

It won't go through AT ALL and says "You left a lot of fields blank (my own echo message)".

Link to comment
Share on other sites

Those are parantheses. o.o

And I know they mean something in PHP. That's why I'm using them 0.o I don't see your posts useful at all.

They are just staying obvious things I already have.

() - parantheses.

{} - curly braces

[] - brackets.


Terminology helps when explaining something to people.

Link to comment
Share on other sites

They are also known as parentheses. They are, however, brackets. In the English language, they are the most common form of bracket, therefor, I find calling them round brackets to be redundant.


You see, you posted an error, then later corrected that error in the post by removing the erroneous bracket. You didn't however, mention that you were no longer getting the error.


I provided the solution to the only error your original post, thus my post was very helpful. If you couldn't see that, I don't see how it could be considered an issue with the helper.


I also guided you to finding the solution to your later problem. There is obviously an issue with the way you've positioned your brackets within the statement.

As far as your edit goes, where you've now fixed this problem, you obviously have a variable empty that shouldn't be. Perhaps verifying what the variables you're checking contain?

Link to comment
Share on other sites

xyph's posts are valid and you should listen instead of putting down those who point you in the right direction. 

41. if(!(empty($name)
is not valid.


It is valid, it just wont result in the behavior he expects. That will return true if the result in the brackets returns false.

Link to comment
Share on other sites

if(!empty($name) && !empty($username) && !empty($password) && !empty($password2) && !empty($email) && !empty($email2) && !empty($gender) && !empty($security) && !empty($adminpw))


the code inside this IF statement executes only if none of these variables[$name,$username,etc] are empty. Try printing these variables to check if they are empty. i guess these are coming from form fields. So in this page check whether the fields are empty or not. Moreover, if you have not used extract function, you need to check the variables you've assigned to fetch the form variables[$name,$username,etc].

echo "<pre>";
print_r($_POST); //if you have used GET method in form then use $_GET instead
echo "</pre>";


MOREOVER, if you paste few lines of codes above and below that IF statement will help us debug it. Like code from

// your codes here
} //end of checking $_POST["submit"]

Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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