Registration in the BD with pre-filled fields

Asked

Viewed 127 times

0

I’m creating a system of registration on top of a system I found on the Net. In my system there are only 2 fields e-mail and password, and the password will already be pre-registered, missing so only the user fill the email. I’m having problems when I consult the database, because I can not feed this information e-mail, follow code where I doubt how to make this query.

if (!$this->db_connection->connect_errno) {
// escaping, additionally removing everything that could be (html/javascript-) code
    $user_email = $this->db_connection->real_escape_string(strip_tags($_POST['user_email'], ENT_QUOTES));
    $user_password = $_POST['user_password_new'];

    $sql = "SELECT * FROM users WHERE user_pass = '" . $user_password . "';";
    $query_check_user_password = $this->db_connection->query($sql);

    if ($query_check_user_password->num_rows == 1) {
        // check if user or email address already exists
        $sql = "SELECT * FROM users WHERE user_email = '" . $user_email . "';";
        $query_check_user_name = $this->db_connection->query($sql);

        if ($query_check_user_name->num_rows == 1) {
            $this->errors[] = "Sorry, that email address is already taken.";
        } else {
            // write new user's data into database
            $sql = "INSERT INTO users (user_pass, user_email) VALUES('" . $user_password . "', '" . $user_email . "');";
            $query_new_user_insert = $this->db_connection->query($sql);

            // if user has been added successfully
            if ($query_new_user_insert) {
                $this->messages[] = "Your account has been created successfully. You can now log in.";
            } else {
                $this->errors[] = "Sorry, your registration failed. Please go back and try again.";
            }
        }
    }else {
        $this->errors[] = "Sorry, that password is invalid.";
    }
}
  • When you try to record a new record it error or email value is written blank?

  • He gives the message "Sorry, your Registration failed. Please go back and Try Again." For Else { $this->errors[] = "Sorry, your Registration failed. Please go back and Try Again." ; }

  • Leave your code like this to display the bank error message $query_new_user_insert = $this->db_connection->query($sql) or die(mysql_error()); if using mysql_* functions, if mysqli uses mysqli_error($conexao)

  • 1

    A question, this is by chance a password change stream where it informs the previous password and the new password?

  • No, it’s not a password change flow.

1 answer

1


I don’t know if I understand you but if what you want is just to insert the email is like this:

 if (!$this->db_connection->connect_errno) {

    $user_email = $this->db_connection->real_escape_string(strip_tags($_POST['user_email'], ENT_QUOTES));
    $user_password = $_POST['user_password_new'];

    $sql = "SELECT * FROM users WHERE user_pass = '" . $user_password . "';";
    $query_check_user_password = $this->db_connection->query($sql);

    if ($query_check_user_password->num_rows == 1) {
        // check if user or email address already exists
        $sql = "SELECT * FROM users WHERE user_email = '" . $user_email . "';";
        $query_check_user_name = $this->db_connection->query($sql);

        if ($query_check_user_name->num_rows == 1) {
            $this->errors[] = "Sorry, that email address is already taken.";
        } else {
            // write new user's data into database
            $sql = "UPDATE users SET user_email = '". $user_email . "' WHERE user_pass = '". $user_password ."';";
            $query_new_user_insert = $this->db_connection->query($sql);

            // if user has been added successfully
            if ($query_new_user_insert) {
                $this->messages[] = "Your account has been created successfully. You can now log in.";
            } else {
                $this->errors[] = "Sorry, your registration failed. Please go back and try again.";
            }
        }
    }else {
        $this->errors[] = "Sorry, that password is invalid.";
    }
}
  • But before entering the email I wanted to check if the password that it will fill in the form is the same as that in the registered bank

  • the password will be unique for each record ? if that’s where you have to update the email and not Insert

  • each user will have a different password, it will with this password in the system and register your email.

  • so it’s really update, I edited the code, see if that’s it

  • 2

    It worked out that’s right!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.