Welcome Guest, Not a member yet? Register   Sign In
insert() return null
#1

(This post was last modified: 06-01-2020, 02:45 PM by jreklund.)

Hello,
i using CI4 and i call method insert() and i set all required params but function return 0! why? how i can get error message if is exist!
My code is:
PHP Code:
namespace App\Models;
use 
CodeIgniter\Database\ConnectionInterface;
use 
CodeIgniter\Model;

class 
UserModel extends Model
{

    protected $table 'users';
protected 
$primaryKey 'id';
    protected $allowedFields = ['role''email','password','display_name','active','token'];
protected 
$useSoftDeletes true;
protected 
$returnType 'array';
protected 
$useTimestamps true;
    protected $createdField  'created_at';
protected 
$deletedField  'deleted_at'

PHP Code:
$signup_email=$this->request->getVar('signup_email');
$signup_password=$this->request->getVar('signup_password');
$signup_password_confirmation=$this->request->getVar('signup_password_confirmation');
$val $this->validate([
'signup_email' => ['label' => 'Email''rules' => 'trim|required|valid_email'], 
'signup_password' => ['label' => 'Password''rules' => 'trim|required'],
'signup_password_confirmation' => ['label' => lang('app.field_confirm_password'), 'rules' => 'trim|required|matches[signup_password]']
]);
if (!
$val)
{

$validation=$this->validator;
$error_msg=$validation->listErrors();
$res=array("error"=>true,"validation"=>$error_msg);
}
else{
$UserModel=new UserModel();

$data = [
 
'display_name' => $signup_email,
 
'email'  => $signup_email,
 
'password'  => md5($signup_password),
 
'role'=>'customer',
 
'active'=>'no'
 
 
];
$user_id =$UserModel->insert($data);
$res=array("error"=>false,"validation"=>$user_id);


Reply
#2

returns - bool - TRUE on success, FALSE on failure

I would double check your coding.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(05-30-2020, 08:24 AM)InsiteFX Wrote: returns - bool - TRUE on success, FALSE on failure

I would double check your coding.
 is return true but nothing added in table users in DB!!
Reply
#4

(05-30-2020, 08:26 AM)pws Wrote:  is return true but nothing added in table users in DB!!

If it returns 0 (like you said in the start) then it is returning false. 0==false
Reply
#5

(05-30-2020, 11:56 AM)dave friend Wrote:
(05-30-2020, 08:26 AM)pws Wrote:  is return true but nothing added in table users in DB!!

If it returns 0 (like you said in the start) then it is returning false.  0==false
how i can know what's the error exactly? have method to return sql  error?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB