Cyberspace Posted April 12, 2008 Share Posted April 12, 2008 I have a form that validates on submit and then send the information to the database, one of the checks validates that the user is not already added to the database ie "User is already on walk" this works fine but i have a message that is outputted when the form is submit and no errors have occurred, "You has been successfully added to the walk program", this appears if the "User is already on walk" error has occurred, i need "You has been successfully added to the walk program" to only appear if no errors have occurred. Can anyone help? Code is <?php if (isset($_POST['submit'])) { $error_stat = 0; $message = 0; $MemberRef_message = ''; $Password_message = ''; $Password2_message = ''; $User_message = ''; $Walk_message = ''; $Add_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*'; } 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 password $Password_message = '*Please enter a Password*'; } // Walker Check if (isset($_POST['submit']) && $error_stat == 0) { $account = mysql_query("SELECT * FROM walker WHERE MemberRef='$MemberRef'"); $numrows = mysql_num_rows($account); //get rows returned if($numrows == 0) { $error_stat = 1; $Walk_message = '*Member Ref number does not exist*'; } // MemberRef and Password Check else if (isset($_POST['submit']) && $error_stat == 0) { $account = mysql_query("SELECT * FROM members WHERE MemberRef='$MemberRef' AND Password='$Password'"); $numrows = mysql_num_rows($account); //get rows returned if($numrows == 0) { $error_stat = 1; $User_message = '*Incorrect Password*'; } if (isset($_POST['submit']) && $error_stat == 0) { $account = mysql_query("SELECT * FROM walker WHERE MemberRef='$MemberRef' AND WalkNo='$WalkNo'"); $numrows = mysql_num_rows($account); //get rows returned if($numrows == 1) { $error_stat = 1; $Walk_message = '*User is already on walk*'; } if (isset($_POST['submit']) && $error_stat == 0) { mysql_query("INSERT INTO walker (MemberRef, WalkNo, DateJoined) VALUES ('$MemberRef', '$WalkNo',NOW())"); } echo "<h4>You has been successfully added to the walk program</h4>"; } } } } ?> <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> <span class="redboldtxt"><?php echo "$Password2_message";?></fieldset></span> <fieldset> <p class="submit"><input type="submit" name="submit" value="Join Walk" /> <span class="redboldtxt"><?php echo "$User_message";?></fieldset></span> <p></p> <span class="redboldtxt"><?php echo "$Walk_message";?></fieldset></span> <span class="redboldtxt"><?php echo "$Add_message";?></fieldset></span> </fieldset> </fieldset> </form> Link to comment https://forums.phpfreaks.com/topic/100783-form-submit-problem/ Share on other sites More sharing options...
Sam Granger Posted April 12, 2008 Share Posted April 12, 2008 you have the following code: if (isset($_POST['submit']) && $error_stat == 0) { mysql_query("INSERT INTO walker (MemberRef, WalkNo, DateJoined) VALUES ('$MemberRef', '$WalkNo',NOW())"); } echo "<h4>You has been successfully added to the walk program</h4>"; Try replacing it with: if (isset($_POST['submit']) && $error_stat == 0) { mysql_query("INSERT INTO walker (MemberRef, WalkNo, DateJoined) VALUES ('$MemberRef', '$WalkNo',NOW())"); echo "<h4>You has been successfully added to the walk program</h4>"; } Link to comment https://forums.phpfreaks.com/topic/100783-form-submit-problem/#findComment-515453 Share on other sites More sharing options...
Cyberspace Posted April 12, 2008 Author Share Posted April 12, 2008 you have the following code: if (isset($_POST['submit']) && $error_stat == 0) { mysql_query("INSERT INTO walker (MemberRef, WalkNo, DateJoined) VALUES ('$MemberRef', '$WalkNo',NOW())"); } echo "<h4>You has been successfully added to the walk program</h4>"; Try replacing it with: if (isset($_POST['submit']) && $error_stat == 0) { Hey thanks for that, this is abit of topic but is there anyway i can refresh the screen once the submit button is click and the record is added to the database, i have a table above that ouputs the records that have been added. mysql_query("INSERT INTO walker (MemberRef, WalkNo, DateJoined) VALUES ('$MemberRef', '$WalkNo',NOW())"); echo "<h4>You has been successfully added to the walk program</h4>"; } Link to comment https://forums.phpfreaks.com/topic/100783-form-submit-problem/#findComment-515461 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.