0

In creating a user account I want it to check if the user name is already taken if yes then it must inform the account creator that it is already taken, if not then it should proceed.

<div class="form-group row">
  <label class="col-12 col-sm-3 col-form-label text-sm-right">Username</label>
  <div class="col-12 col-sm-8 col-lg-6">
  <input data-parsley-type="alphanum" type="text" name="username" pattern="(?=.*[a-z]).{10, }.+" required="" placeholder="" class="form-control" />
   </div>
</div>

I think this js is totally wrong in incomplete but here it is. please help me fix this

    <script>
        $.post('class_model.php', { username: username}, function(data) {
    if (data == 'yes') {

    } else {

    }
    });
    </script>

here's my class_model.php file

public function add_user($complete_name, $desgination, $email_address, $phone_number, $username, $password, $status){
    $stmt = $this->conn->prepare("INSERT INTO `tbl_usermanagement` (`complete_name`, `desgination`, `email_address`, `phone_number`, `username`, `password`, `status`) VALUES(?, ?, ?, ?, ?, ?, ?)") or die($this->conn->error);
    $stmt->bind_param("sssssss", $complete_name, $desgination, $email_address, $phone_number, $username, $password, $status);
    if($stmt->execute()){
    $stmt->close();
    $this->conn->close();
    return true;

}
}

VLAZ
  • 26,331
  • 9
  • 49
  • 67
yumie
  • 3
  • 1
  • You don't typically POST to a class file itself, rather it would be to a page that calls that class file. You don't show where you check for duplicate usernames ( there is no select statement shown ) nor do you show where any content is sent back to the ajax callback. This makes the question impossible to really answer – Professor Abronsius Dec 02 '22 at 08:43

0 Answers0