Jump to content

Recommended Posts

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]

Link to comment
https://forums.phpfreaks.com/topic/53562-form-validation/
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.