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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

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