Jump to content

Recommended Posts

Hello Guys, great forum, first time posting here :-)

 

I'm creating a php registration form, and I'm doing some validations. The problem on my code is the following:

 

When the password is mimatched with the password_again, the following if is executed (referring the email validation). But when the password is matched with the password_again, the email validation isn't running. Why php is not executing the if when the passwords are OK?

<?php
if(!empty($_POST['username']) && !empty($_POST['password']))
  {
  $username = mysql_real_escape_string($_POST['username']);
  $password = md5(mysql_real_escape_string($_POST['password']));
  $email = mysql_real_escape_string($_POST['email']);
  
  $check_username = mysql_query("SELECT * FROM users WHERE username = '".$username."'");
  
    if(mysql_num_rows($check_username) == 1)
      {
      echo "<h1>Error</h1>";
      echo "<p> Username is already in use, click <a href=\"register.php> here</a> to try again!</p>";
      }
      if($_POST['password'] === $_POST['password_again'])
        {
        return true;
        }
      else
        {
        echo "Passwords do not match. Please click <a href=\"register.php\">here</a> to try again<br/>";
        }
      if (isset($_POST['email']))
         {
      if (isValidEmail($_POST['email']))
            {
            return true;
            }
      else
            {
            echo "<p><tr><td>The email: ".$_POST['email']." is invalid!</td></tr> Please click <a href=\"register.php\">here</a> to try again</p>";
            }
         }
    else
      {
      $write = mysql_query("INSERT INTO users (username, password, email) VALUES('".$username."', '".$password."', '".$email."')");
        if($write)
        {
        echo "<p> Account created! Click <a href=\"index.php\">here</a> to login.</p>";
        echo "<meta http-equiv='refresh' content='=4;index.php' />";
        }
        else
        {
        echo "<p> There was an error. Please click <a href=\"register.php\">here</a> to try again.</p>";
        }
       }
   }
   else
   {
      ?>

 

Link to comment
https://forums.phpfreaks.com/topic/212020-problem-on-validation-with-php/
Share on other sites

      if($_POST['password'] === $_POST['password_again'])
        {
        return true;
        }

 

That code - which I copied from your original post - says: "If the passwords match, RETURN - leave - quit - do NOT run the email check which is the next statement"

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.