Jump to content

Error variable I coded doesnt work. why?! ): ): ):


Minimeallolla

Recommended Posts

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

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.

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.