Jump to content

PHP Registration form


aerouk

Recommended Posts

Hey all,

 

I'm a little stuck with a form that I'm playing with at the moment. Just a few fields with a small bit of validation. However I seem to keep being faced with the deaded WPE!

 

Could someone please let me know whats going on with the below?

 

if(isset($_POST['submit'])){
    # connect to the database here
    include('db.php');
    # search the database to see if the user name has been taken or not
    $sql= mysql_query("SELECT * FROM ffl_managers WHERE userName='{$_POST['user_name']}' LIMIT 1");
    $row = mysql_fetch_array($sql)or die(mysql_error());
    #check to see what fields have been left empty, and if the passwords match
    if($row||empty($_POST['user_name'])||
    empty($_POST['fname'])||empty($_POST['lname'])||
    empty($_POST['email'])||empty($_POST['password'])||
    empty($_POST['re_password'])||$_POST['password']!=$_POST['re_password']){
        # if a field is empty, or the passwords don't match make a message
        if(empty($_POST['user_name'])){
            $user = 'User Name cant be empty<br>';
        }
        if(empty($_POST['fname'])){
            $fname = 'First Name cant be empty<br>';
        }
        if(empty($_POST['lname'])){
            $lname = 'Last Name cant be empty<br>';
        }
        if(empty($_POST['email'])){
            $email = 'Email cant be empty<br>';
        }
        if(empty($_POST['password'])){
            $password = 'Password cant be empty<br>';
        }
        if(empty($_POST['re_password'])){
            $re_password = 'You must re-type your password<br>';
        }
        if($row){
            $user_name_exist = 'User Name already exists<br>';
        }
        if($_POST['password']!=$_POST['re_password']){
            $password_match = 'Passwords dont match<br>';
        }
    }else{
        # If all fields are not empty, and the passwords match,
        # create a session, and session variables,
        # register_accept will be checked on the next page to see
        # if the user came from this page.
        session_start();
        $_SESSION['user_name'] = $_POST['user_name'];
        $_SESSION['fname'] = $_POST['fname'];
        $_SESSION['lname'] = $_POST['lname'];
        $_SESSION['email'] = $_POST['email'];
        $_SESSION['password'] = $_POST['password'];
        $_SESSION['memorable_word'] = $_POST['memorable_word'];
        $_SESSION['register_accept'] = 1;
        header("Location: confirm_join.php");
        exit;
    }
}
# echo out each variable that was set from above,
# then destroy the variable.
if(isset($user)){
    echo $user;
    unset($user);
}
if(isset($fname)){
    echo $fname;
    unset($fname);
}
if(isset($lname)){
    echo $lname;
    unset($lname);
}
if(isset($email)){
    echo $email;
    unset($email);
}
if(isset($password)){
    echo $password;
    unset($password);
}
if(isset($re_password)){
    echo $re_password;
    unset($re_password);
}
if(isset($user_name_exist)){
    echo $user_name_exist;
    unset($user_name_exist);
}
if(isset($password_match)){
    echo $password_match;
    unset($password_match);
}
if(isset($memorable_word)){
    echo $memorable_word;
    unset($memorable_word);
}
?> 
<!-- Start your HTML/CSS/JavaScript here -->
<form action="registration.php" method="post">
    <p>First Name:<br><input type="text" name="fname" 
    <? echo 'value="'.$_POST['fname'].'"'; ?></p>
    <p>Last Name:<br><input type="text" name="lname"  
    <? echo 'value="'.$_POST['lname'].'"'; ?></p>
    <p>Email:<br><input type="text" name="email"  
    <? echo 'value="'.$_POST['email'].'"'; ?></p>
    <p>Desired User Name:<br><input type="text" name="user_name" 
    <? if(!$row){echo 'value="'.$_POST['user_name'].'"';} ?></p>
    <p>Password:<br><input type="password" name="password"  
    <? if($_POST['password']==$_POST['re_password'])
    {echo 'value="'.$_POST['password'].'"';} ?></p>
    <p>Re-Type Password:<br><input type="password" name="re_password"  
    <? if($_POST['password']==$_POST['re_password'])
    {echo 'value="'.$_POST['re_password'].'"';} ?></p>
    <p>Memorable Word:<br><input type="text" name="memorable_word" 
    <? if(!$row){echo 'value="'.$_POST['memorable_word'].'"';} ?></p>
    <p><input type="submit" name="submit" value="Sign Up"></p>
</form>

 

File name is registration.php.

 

Confirm_join is below:

# start the session
session_start();
# check to see if the session on the previous page was created
# if it was created, allow this page to run, otherwise
# redirect the user to the join page.
if($_SESSION['register_accept']!=1){
    header("Location: registration.php");
    exit;
}

# Connect to the database here

# addslashes (Helps protect from SQL injection) and remove html
$user = strip_tags(addslashes($_SESSION['user_name']));
$fname = strip_tags(addslashes($_SESSION['fname']));
$lname = strip_tags(addslashes($_SESSION['lname']));
$email = strip_tags(addslashes($_SESSION['email']));
$password = strip_tags(addslashes($_SESSION['password']));
$memorable_word = strip_tags(addslashes($_SESSION['memorable_word']));

# Insert into the database
mysql_query("INSERT INTO ffl_managers(`userName`,`firstName`,`lastName`,`email`,`password`, `memorableWord`)
            VALUES('$user','$fname','$lname','$email','$password','$memorable_word')or die(mysql_error());
                        
# If you would like to send an email, this would be the place to place it

#redirect the user back to a page where they can login                
header("Location: login.php");
exit;

 

Any thoughts?

 

Aero.

 

Link to comment
Share on other sites

Its receiving the contents if the form is submitted, else it is displaying the form. Once submitted, the script is validating the entries.

 

Be specific if you want to ask anything particular from the code.

 

Link to comment
Share on other sites

You still are not being specific upon what your wanting to achieve. What is the program not doing that you would like it to do? You have yet to specify, no one can help without you answering that question, aerouk.

Link to comment
Share on other sites

Basically - It's not working, its WPE'ing. (White Page Error).

 

It doesnt appear to take the input, validate it and then successfully post to my database. It WPE's upon clicking submit.

 

Can anyone see any glaring errors in the code, or have any suggestions as to how I can fix it?

Link to comment
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.