Minimeallolla Posted December 4, 2010 Share Posted December 4, 2010 I've coded an error variable thing to help with my login but it doesn't work and I am puzzled to why it does not. (>.<) error codes such as: <?php /* checks to see if forms are filled in, if not, create a variable that will be used later. if forms are filled in than the variable is nothing and nothing will be echoed therefore passing onto the next if statement and repeating. */ if(!$_POST['username'] | !$_POST['pass']) { $errormessage_didnotfillinform = ('<center>You did not fill in a required field!</center>'); } else{ $errormessage_didnotfillinform = (''); } ?> <html> <body> <!-- html such as the follow, goes here. --> <div align="center"><b>Log in</b> <form action="" method="post"> <table class="centered" border="0"> <tr><td>Username:</td><td> <input type="text" name="username" maxlength="40"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="pass" maxlength="50"> </td></tr> <tr><td colspan="2" align="right"> <input type="submit" name="submit" value="Login"> </td></tr></table> </form></div> </body> </html> <?php echo ( $errormessage_didnotfillinform ); if ( $errormessage_didnotfillinform ) == ('') { echo ( $errormessage_accountdoesnotexist ); } if ( $errormessage_accountdoesnotexist ) == ('') { echo ( $errormessage_invalidusernameorpassword ); } ?> Quote Link to comment Share on other sites More sharing options...
Minimeallolla Posted December 4, 2010 Author Share Posted December 4, 2010 To me, it seems perfect but I don't understand why it doesn't work ): Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted December 4, 2010 Share Posted December 4, 2010 You need to start by using the proper operator. An 'or' is || not | . . . Quote Link to comment Share on other sites More sharing options...
Minimeallolla Posted December 4, 2010 Author Share Posted December 4, 2010 ok thanks, so its if(!$_POST['username'] || !$_POST['pass']) { not if(!$_POST['username'] | !$_POST['pass']) { ? lol Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted December 4, 2010 Share Posted December 4, 2010 Yes. Quote Link to comment Share on other sites More sharing options...
Minimeallolla Posted December 4, 2010 Author Share Posted December 4, 2010 lol ok, anything else? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted December 4, 2010 Share Posted December 4, 2010 Yes. The way you have it coded, as little as a single space is a valid value, and will validate. Also, it would be better to store the errors in an array, then you can just check whether the array is empty to determine if there have been any validation errors. Quote Link to comment 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.