Jump to content

Register Problem. Help


tebrown

Recommended Posts

Ok so im working on this register script and trying to implement a select value field along with a email field and password field. At the moment i have given it my best shot and typed in most of the code, although im still not satisfied with the outcome.

 

For example: When i type in a correct email with a legit password, and i DONT select one of the drop down options, i want it to say the error: "Please type in all fields.". This would be vise versa for each other field also!

 

If the user again types in a legit email and password, and selects a value from the dropdown menu, but is already registered in the database, i would want another error message saying: "This club has already been registered to the database".

 

I given it my best shot but simply not getting the above result.

 

<?php include"database.php";?>

   

<html>

<head>

<title>Register</title>

</head>

<body>

 

<h1>Register</h1>

<form name="register" action="register.php" method="post">

Email: <input type="text" name="email"><br>

Password: <input type="password" name="password"><br>

Club: <select name="club">

    <option value="">Select...</option>

    <option value="npob">Old Boys</option>

    <option value="tukupa">Tukupa</option>

    <option value="coastal">Coastal</option>

    <option value="inglewood">Inglewood</option>

    <option value="clifton">Clifton</option>

    <option value="stratford">Stratford</option>

    <option value="hawera">Hawera</option>

  </select><br>

<input type='submit' name='submit' value='Submit'>

</form>

   

<?php

    if (isset($_POST['submit'])) {

       

    if (empty($_POST['email']) && empty($_POST['password']) && empty($_POST['club']))  {

        $errors[] = "Please fill out all fields.";

        }

       

    $email = addslashes(strip_tags($_POST['email']));

    $password = addslashes(strip_tags($_POST['password']));

    $club = addslashes(strip_tags($_POST['club']));

   

    if (!empty($email)) {

        if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {

        $errors[] =  "This email address is not valid.";

        }

        }

   

    if (!empty($password)){

        if (strlen($password)>25 || strlen($password)<6) {

        $errors[] =  "Password must be betwen 6 and 25 characters.<br>";

        }

        }

   

  if (!empty($club)){

        $errors[] =  "Please select a Club.<br>";

        }

 

      $check = mysql_query("SELECT * FROM users WHERE email='".$email."'");

        if (mysql_num_rows($check)>=1) {

        $errors[] =  "Email is already taken!";

        }

 

      $check = mysql_query("SELECT * FROM users WHERE club='".$club."'");

    if (mysql_num_rows($check)>=1) {

    $errors[] =  "Sorry this club has already been registered with the NZRU.";

    }

       

        if (empty($errors)) {

        $register = mysql_query("INSERT INTO users (email, password, club, level) VALUES ('".$email."', '".md5($password)."', '".$club."', '')");

        echo "You have succesfully registered!";

                   

        } else {

                       

        foreach($errors as $nErrors){

        echo $nErrors . "<br>";

                        }

                    }

                }

?>

 

Thankyou.

Link to comment
Share on other sites

Sorry about the above code. Here it is:

 

<?php include"database.php";?>
     
<html>
<head>
<title>Register</title>
</head>
<body>

<h1>Register</h1>
<form name="register" action="register.php" method="post">
Email: <input type="text" name="email"><br>
Password: <input type="password" name="password"><br>
Club: <select name="club">
    <option value="">Select...</option>
    <option value="npob">Old Boys</option>
    <option value="tukupa">Tukupa</option>
    <option value="coastal">Coastal</option>
    <option value="inglewood">Inglewood</option>
    <option value="clifton">Clifton</option>
    <option value="stratford">Stratford</option>
    <option value="hawera">Hawera</option>
  </select><br>
<input type='submit' name='submit' value='Submit'>
</form>
     
<?php
     if (isset($_POST['submit'])) {
         
     if (empty($_POST['email']) && empty($_POST['password']) && empty($_POST['club']))  {
         $errors[] = "Please fill out all fields.";
         }
         
     $email = addslashes(strip_tags($_POST['email']));
     $password = addslashes(strip_tags($_POST['password']));
     $club = addslashes(strip_tags($_POST['club']));
     
     if (!empty($email)) {
         if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
         $errors[] =  "This email address is not valid.";
         }
         }
     
     if (!empty($password)){
         if (strlen($password)>25 || strlen($password)<6) {
         $errors[] =  "Password must be betwen 6 and 25 characters.<br>";
         }
         }
     
  if (!empty($club)){
         $errors[] =  "Please select a Club.<br>";
         }

      $check = mysql_query("SELECT * FROM users WHERE email='".$email."'");
         if (mysql_num_rows($check)>=1) {
         $errors[] =  "Email is already taken!";
         }

      $check = mysql_query("SELECT * FROM users WHERE club='".$club."'");
     if (mysql_num_rows($check)>=1) {
     $errors[] =  "Sorry this club has already been registered with the NZRU.";
     }
         
         if (empty($errors)) {
         $register = mysql_query("INSERT INTO users (email, password, club, level) VALUES ('".$email."', '".md5($password)."', '".$club."', '')");
         echo "You have succesfully registered!";
                     
         } else {
                         
         foreach($errors as $nErrors){
         echo $nErrors . "<br>";
                         }
                     }
                 } 
?>

Link to comment
Share on other sites

if (empty($_POST['email']) && empty($_POST['password']) && empty($_POST['club']))  {
         $errors[] = "Please fill out all fields.";
         }

 

This statement says that they all need to be empty for them to work you need to use or which is || not and which you have &&

 

if (empty($_POST['email']) || empty($_POST['password']) || empty($_POST['club']))  {
         $errors[] = "Please fill out all fields.";
         }

 

That will trigger if one of them is empty, also your form processing should really be at the top of the page

Link to comment
Share on other sites

Thanks for the reply.

 

Ok i did that, although how do i make it so that the dropdown first value is default.... (so its like a field with nothing in it and they must pick a option for it to be active) ??

 

The attachment below shows that when i press submit with everything not touched its shows these two errors:

 

post-132578-13482403350261_thumb.png

Link to comment
Share on other sites

If you are asking me for it to display an error if they haven't selected anything in the drop down

 

if (!empty($club)){
         $errors[] =  "Please select a Club.<br>";
         }

 

should be

 

if ($club == ''){
         $errors[] =  "Please select a Club.<br>";
         }

 

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.