PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, January 18, 2022

[FIXED] insert hashed password while register in codeigniter

 January 18, 2022     codeigniter, php     No comments   

Issue

I have user pannel in a codeigniter. where user have a option to register. i want to user's password to hashed in my database. i have done the registeration with normal password but i want now password to be hashed. I have taken help with similar questions but resulted into an error

controller


    public function signupvalidation()
    {
        $this->load->library('form_validation');

        if($this->form_validation->run('userregister'))
        {
           $post = $this->input->post();
           $this->load->model('userregister');
           if($this->userregister->register1($post))
           {
                echo "insert succesfully";
           }

           else
           {
            echo "not succesfully";
           }
           $this->session->set_flashdata('insertsuccess','User Registration Successfully');
          return redirect('user/signup');
        }
        else
        {      
                $this->load->view('user/usersignup');
        }
        
    }

model


    private function hash_password($password){
        return password_hash($password, PASSWORD_BCRYPT);
     }
     public function register1($name,$email,$password){
        $data = array(
          'name' => $name,
           'email' => $email,
          'password' => $this->hash_password($password)
     );
     return $this->db->insert('user', $data);
     }

the error i have got

An uncaught Exception was encountered
Type: ArgumentCountError

Message: Too few arguments to function userregister::register1(), 1 passed in C:\xampp\htdocs\blog\application\controllers\user.php on line 84 and exactly 3 expected

Filename: C:\xampp\htdocs\blog\application\models\userregister.php

Line Number: 14

Backtrace:

File: C:\xampp\htdocs\blog\application\controllers\user.php
Line: 84
Function: register1

File: C:\xampp\htdocs\blog\index.php
Line: 315
Function: require_once

please help how to do it


Solution

Error message clearly state that your model method required three arguments and you supplied just one.

In your controller

if($this->userregister->register1($post))

change it to

if($this->userregister->register1($post['name'], $post['email'], $post['password']))

I am assuming that $post is an array of $_POST.



Answered By - mail2bapi
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing