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
https://forums.phpfreaks.com/topic/259476-register-problem-help/
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>";
                         }
                     }
                 } 
?>

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

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

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>";
         }

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.