Cyberspace Posted April 9, 2008 Share Posted April 9, 2008 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 More sharing options...
Cyberspace Posted April 9, 2008 Author Share Posted April 9, 2008 I want the error message for "User_message" to only appear if both the MemberRef and password fields are completed and then check if the user exists on the database and out the error if necessary. Link to comment https://forums.phpfreaks.com/topic/100331-form-validation-help/#findComment-513049 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.