Jump to content

Form validation help


Cyberspace

Recommended Posts

Im trying to validate a form that checks if a user has added a MemberRef and a Password, and then check a table to check that user exists in the database, can anyone please help?

 

My code is:

 

<?php


if (isset($_POST['submit'])) {  

$error_stat = 0;  
    $MemberRef_message = ''; 
    $Password_message = '';
    $User_message = '';

    $MemberRef = mysql_real_escape_string(stripslashes($_POST['MemberRef']));
    $Password = mysql_real_escape_string(stripslashes($_POST['Password']));
    
//Error checking  

// MemberRef Check)  
if (!$MemberRef) { 
//Set the error_stat to 1, which means that an error has occurred 
    $error_stat = 1; 

//Set the message to tell the user to enter a username 
    $MemberRef_message = '*Please enter MemberRef*'; 
} 

else if (!ctype_digit($MemberRef)) {  
   $error_stat = 1;  
   $MemberRef_message .= '*MemberRef must be a number*';  
} 


// Password Check)  
if (!$Password) { 
//Set the error_stat to 1, which means that an error has occurred 
    $error_stat = 1; 

//Set the message to tell the user to enter a username 
    $Password_message = '*Please enter a password*'; 
} 

$account = mysql_query("SELECT * FROM members WHERE MemberRef='$MemberRef' &&  Password='$Password'");

    if(mysql_num_rows($account) == 0){
         $error_stat = 1;
//Set the message to tell the user MemberRef does not exist 
    $User_message = '*MemberRef does not exist*';
} 
}



?>


<hr class="hr_blue"/></p><font face="Arial" size="3">Join Walk</font><form method="post" class="addwalkerform" action="">   
</font>
<fieldset>
<label for="MemberRef">MemberRef:</label>  
<input name="MemberRef" type="text" id="MemberRef" value="<?php echo $_POST['MemberRef']; ?>"/> 
<span class="redboldtxt"><?php echo "$MemberRef_message";?></fieldset></span>  
</fieldset>

<fieldset>
<label for="Password">Password:</label>  
<input name="Password" type="text" id="Password" value="<?php echo $_POST['Password']; ?>"/> 
<span class="redboldtxt"><?php echo "$Password_message";?></fieldset></span>
<p></p>
<fieldset> 
<p class="submit"><input type="submit" name="submit" value="Join Walk" />

<span class="redboldtxt"><?php echo "$User_message";?></fieldset></span>


</fieldset>


</fieldset>
</form>

<?php
}
?>

Link to comment
https://forums.phpfreaks.com/topic/100331-form-validation-help/
Share on other sites

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.