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 ); } ?> Link to comment https://forums.phpfreaks.com/topic/220624-error-variable-i-coded-doesnt-work-why/ 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 ): Link to comment https://forums.phpfreaks.com/topic/220624-error-variable-i-coded-doesnt-work-why/#findComment-1142814 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 | . . . Link to comment https://forums.phpfreaks.com/topic/220624-error-variable-i-coded-doesnt-work-why/#findComment-1142828 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 Link to comment https://forums.phpfreaks.com/topic/220624-error-variable-i-coded-doesnt-work-why/#findComment-1142830 Share on other sites More sharing options...
Pikachu2000 Posted December 4, 2010 Share Posted December 4, 2010 Yes. Link to comment https://forums.phpfreaks.com/topic/220624-error-variable-i-coded-doesnt-work-why/#findComment-1142838 Share on other sites More sharing options...
Minimeallolla Posted December 4, 2010 Author Share Posted December 4, 2010 lol ok, anything else? Link to comment https://forums.phpfreaks.com/topic/220624-error-variable-i-coded-doesnt-work-why/#findComment-1142850 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. Link to comment https://forums.phpfreaks.com/topic/220624-error-variable-i-coded-doesnt-work-why/#findComment-1143021 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.