Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8361469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:42:32+00:00 2026-06-09T11:42:32+00:00

I have a register form which is post data without refresh page! My problem

  • 0

I have a register form which is post data without refresh page! My problem form reset datas. It works on username and keeping user’s entry. I try to do same thing for “gender” too, but if i get eror, “Genderselection get reset too.I couldn’t manage keep it.

Can anyone help me please?

My code is below:

/* Current Page */
    public function currentPage() {
        /* Current Page */
        $currentPage  = 'http';
        if(isset($_SERVER["HTTPS"]) == "on") {$currentPage .= "s";}
        $currentPage .= "://";
        $currentPage .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
        return $currentPage;
    }

    /* Register */
    public function register() {
    global $database;

    /* Set Message Array */
    $message = array();

    /* Check if Login is set */
    if(isset($_POST['register'])) {

    /* Check Username */
    if(!empty($_POST['username'])) {

    $check_username = strtolower($_POST['username']);

    /* Check the username length */
    $length = strlen($check_username);
    if($length >= 5 && $length <= 25) {

    /* Is the username Alphanumeric? */
    if(preg_match('/[^a-zA-Z0-9_]/', $check_username)) {
    $error[] = "Please enter a valid alphanumeric username";
    $username = null;
    } else {
    $database->query('SELECT id FROM users WHERE username = :username', array(':username' => $check_username));

    /* Check if user exist in database */
    if($database->count() == 0) {

    /* Require use to validate account */
    if($this->email_verification == true) {

    /* Check if user exist in inactive database */
    $database->query('SELECT date FROM users_inactive WHERE username = :username', array(':username' => $check_username));

    /* If user incative is older than 24 hours */

    $user = $database->statement->fetch(PDO::FETCH_OBJ);
    if($database->count() == 0 or time() >= strtotime($user->date) + 86400) {

    /* If user incative is older than 24 hours */
    $username = $_POST['username'];
    } else {
    $error[] = "Username already in use";
    $username = $check_username;
    }
    } else {
    $username = $_POST['username'];
    }
    } else {
    $error[] = "Username already in use";
    $username = $check_username;
    }
    }
    } else {
    $error[] = "Please enter a username between 5 to 25 characters";
    $username = $check_username;
    }
    } else {
    $error[] = "Please enter a username";
    $username = null;
    }

    /* Check Password */
    if(!empty($_POST['password'])) {

    /* Do passwords match? */

    if(isset($_POST['password_again']) && $_POST['password_again'] == $_POST['password']) {

    /* Is the password long enough? */
    $length = strlen($_POST['password']);
    if($length >= 8) {
    $password = $_POST['password'];
    } else {
    $error[] = "Passwords must be atleast than 8 characters";
    }
    } else {
    $error[] = "Passwords must match";
    }
    } else {
    $error[] = "Please enter a password";
    }


    /* Check Gender */
    if(empty($_POST['gender'])) {
    $error[] = "Please choose your gender";
    }else{

    $gender = $_POST['gender'];

                }


    $form = '
    <form name="register" action="' . $this->currentPage() . '" method="post">
    <label><span>Username</span>
    <input type="text" name="username" value="' . $username . '" />
    </label>

    <label><span>Password</span>
    <input type="password" name="password" />
    </label>

    <label><span>Password Again</span>
    <input type="password" name="password_again" />
    </label>

    <label><span>Gender:</span>
    <select name="gender" value="' . $gender . '">
    <option value="">Choose</option>
    <option value="Male">Male</option>
    <option value="Female">Female</option>

    <input name="register" type="submit" value="Register" />
    </form>
            ';
            /* Combine Data */
            $data = "";
            /* Report any Info */
            if(isset($info)) {
                foreach($info as $message) {
                $data .= '<div class="notice info">' . $message . '</div>';
                }
            }
            /* Report any Errors */
            if(isset($error)) {
                foreach($error as $message) {
                $data .= '<div class="notice error">' . $message . '</div>';
                }
            }
            /* Report any Success */
            if(isset($success)) {
                foreach($success as $message) {
                $data .= '<div class="notice success">' . $message . '</div>';
                }
            }

            /* Return data */
            return $data;
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T11:42:34+00:00Added an answer on June 9, 2026 at 11:42 am

    Regarding your “gender” value problem – You need to change this code

    <select name="gender" value="' . $gender . '">
        <option value="">Choose</option>
        <option value="Male">Male</option>
        <option value="Female">Female</option>
    

    To

    <select name="gender">
        <option value="" ' .($gender == '' ? 'selected="selected"' : '') . '>Choose</option>
        <option value="Male" ' .($gender == 'male' ? 'selected="selected"' : '') . '>Male</option>
        <option value="Female" ' .($gender == 'female' ? 'selected="selected"' : '') . '>Female</option>
    

    You are trying to set a value to select tag which is invalid.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Create new account page. The form is in page named Register.php
I have a form which I'm using jQuery to post and working to handle
I have page register.php, which is used to get user informations, after completion of
I have a form which allows users to comment on a page, however they
I have a problem in creating an AJAX-based form submission which if its response
I have a register page in which via ajax request i want to redirect
I have a user registration form in my Django application which collects additional data
I have form where before i was using simple post with <button name=submit id=register
I'm trying to figure out how I can turn this: $('#username').blur(function(){ $.post('register/isUsernameAvailable', {username:$('#username').val()}, function(data){
I made register form where you have to put in all your personal info.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.