Tenaciousmug Posted November 5, 2011 Share Posted November 5, 2011 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)) Quote Link to comment https://forums.phpfreaks.com/topic/250524-if-and-ors/ Share on other sites More sharing options...
xyph Posted November 5, 2011 Share Posted November 5, 2011 if(!empty($name)) You're closing your IF statement right there. Quote Link to comment https://forums.phpfreaks.com/topic/250524-if-and-ors/#findComment-1285318 Share on other sites More sharing options...
nethnet Posted November 5, 2011 Share Posted November 5, 2011 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 ||. Quote Link to comment https://forums.phpfreaks.com/topic/250524-if-and-ors/#findComment-1285319 Share on other sites More sharing options...
Tenaciousmug Posted November 5, 2011 Author Share Posted November 5, 2011 Ohh I gotcha nethnet! I understand where you're coming from. And xyph... you need to read my first post o.o Quote Link to comment https://forums.phpfreaks.com/topic/250524-if-and-ors/#findComment-1285320 Share on other sites More sharing options...
Tenaciousmug Posted November 5, 2011 Author Share Posted November 5, 2011 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)) Quote Link to comment https://forums.phpfreaks.com/topic/250524-if-and-ors/#findComment-1285322 Share on other sites More sharing options...
nethnet Posted November 5, 2011 Share Posted November 5, 2011 Give us a few lines of code above and below that, with line numbers, as well as the exact error messages again. Quote Link to comment https://forums.phpfreaks.com/topic/250524-if-and-ors/#findComment-1285323 Share on other sites More sharing options...
Tenaciousmug Posted November 5, 2011 Author Share Posted November 5, 2011 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)". Quote Link to comment https://forums.phpfreaks.com/topic/250524-if-and-ors/#findComment-1285324 Share on other sites More sharing options...
xyph Posted November 5, 2011 Share Posted November 5, 2011 Brackets mean something in PHP. You need to be more careful with your use of them. Quote Link to comment https://forums.phpfreaks.com/topic/250524-if-and-ors/#findComment-1285326 Share on other sites More sharing options...
Tenaciousmug Posted November 5, 2011 Author Share Posted November 5, 2011 xyph, what the heck are you talking about? I'm not using brackets.. o.o Quote Link to comment https://forums.phpfreaks.com/topic/250524-if-and-ors/#findComment-1285327 Share on other sites More sharing options...
xyph Posted November 5, 2011 Share Posted November 5, 2011 Brackets are ( and ) Quote Link to comment https://forums.phpfreaks.com/topic/250524-if-and-ors/#findComment-1285328 Share on other sites More sharing options...
Tenaciousmug Posted November 5, 2011 Author Share Posted November 5, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/250524-if-and-ors/#findComment-1285329 Share on other sites More sharing options...
xyph Posted November 5, 2011 Share Posted November 5, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/250524-if-and-ors/#findComment-1285338 Share on other sites More sharing options...
Drummin Posted November 5, 2011 Share Posted November 5, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/250524-if-and-ors/#findComment-1285341 Share on other sites More sharing options...
xyph Posted November 5, 2011 Share Posted November 5, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/250524-if-and-ors/#findComment-1285344 Share on other sites More sharing options...
watsmyname Posted November 6, 2011 Share Posted November 6, 2011 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]. <?php 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 <?php if(isset($_POST['submit'])) { // your codes here } //end of checking $_POST["submit"] ?> Quote Link to comment https://forums.phpfreaks.com/topic/250524-if-and-ors/#findComment-1285387 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.