skip to Main Content

I creeate an app on android ,database registers user correctly but no email is send out and app displays my error message “cant register user at the moment” don’t know what i am doing wrong
This is part of the php with the registry function

   //function to register and add user email and password to the database
   public function registerUser($name,$email,$password){
     if($this->verifyEmailExists($email,"email") == FALSE){
       //$data = [':name' => $name,':email' => $email,':password' => password_hash($password, PASSWORD_DEFAULT),':date' => date('Y-m-d H:i:s')];
       //$sql = "INSERT INTO tbl_android_users (name, email, password,date) VALUES (:name, :email, :password, :date)";
       //$stmt= $this->db->conn_id->prepare($sql);
       //$stmt->execute($data);
       //$insertid = $this->db->conn_id->lastInsertId();
       $data = array('name' => $name,'email' => $email,'password' => password_hash($password, PASSWORD_DEFAULT),'login_type'=>"email",'date' => date('Y-m-d H:i:s'));
       $this->db->trans_start();
       $this->db->insert('tbl_android_users', $data);
       $insertid = $this->db->insert_id();
       $this->db->trans_complete();
       //echo $insertid; die;
       if ($insertid){
         $this->status = "ok";
         $this->message = "User registered successfully, We sent a verification code to your email address, Click on the link to verify your email address.";
         $this->user = $this->getUpdatedUser($email);
       }else{
         $this->status = "error";
         $this->message = "Cant register user at the moment";
       }
     }else{
       $this->status = "error";
       $this->message = "Email or Phone already exists";
     }

   }

Many thanks in advance

2

Answers


  1. Your if block check fails, as it will only work if $insertid is true. That also means $insertid dataType must be a Boolean.

    I would suggest to put a breakpoint at this line:

    $insertid = $this->db->insert_id();
    

    and try to register a user. See what value the #insertid is. It must be either null or false as that is why the code is failing.

    EDIT

    if your $insertid is null, then check in your repository if the following function returns anything or not:

    $this->db->insert_id()
    

    It logically should returns either a Boolean or the datatype that it is trying to insert as its return.

    Login or Signup to reply.
  2. You should close the transaction before accessing the InsertID property. First execute $this->db->trans_complete(); before you try to get the insertID by using $insertid = $this->db->insert_id();

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search