blackwolf23 Posted May 30, 2007 Share Posted May 30, 2007 Hello, Its been a while since I have done any programming and I have come across a problem that I can't solve. My code listed below is used to check if any fields in the Register form are empty and display a message warning the user. If the fields are not empty then the data should be inserted into the database. I believe my problem lies with this line if ($_POST['_submit_check'] == 1)This line is naturally false when the user is first presented with the Register page and by being false my code skips straight to my Else statement. I know this can be solved easily but I just can't think of a way around it at the moment. Here is my code <?php require_once('Functions.php'); //Post Variables $Username = $_POST['uname']; $Firstname = $_POST['fname']; $Surname = $_POST['sname']; $Email= $_POST['email']; $Password= $_POST['password']; $Cpassword= $_POST['cpassword']; //Function to connect to the database $establish = connect(); //This is the validation code for the form fields if ($_POST['_submit_check'] == 1) { if(strlen($Username) < 6) echo 'Username must be between 6-8 characters'; if(empty($Firstname)) echo 'Firstname is a required field'; if(empty($Surname)) echo 'Surname is a required field'; if(strcmp($Password,$Cpassword) != 0) echo 'Passwords do not match'; } else{ //Query to insert user info into the the database $query = "INSERT into Users (Username,Firstname,Surname,Email,Password) values ('".$Username."','".$Firstname."', '".$Surname."', '".$Email."', '".$Password."' )"; $verify = mysql_query($query); //Now redirect the user to the profile page header('Location: Profile.html'); } [\code] Quote Link to comment https://forums.phpfreaks.com/topic/53562-form-validation/ Share on other sites More sharing options...
pikemsu28 Posted May 30, 2007 Share Posted May 30, 2007 if (isset($_POST['_submit_check']))//_submit_check is the name of the submit button { Quote Link to comment https://forums.phpfreaks.com/topic/53562-form-validation/#findComment-264801 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.