0
votes

I got this message while running my project

Severity: Warning Message: Missing argument 1 for ForgotPassword::FormEditPassword() Filename: controllers/ForgotPassword.php Line Number: 12 Backtrace: File: C:\xampp\htdocs\Telkom\application\controllers\ForgotPassword.php Line: 12 Function: _error_handler File: C:\xampp\htdocs\Telkom\index.php Line: 315 Function: require_once

A PHP Error was encountered Severity: Notice Message: Undefined variable: id_user Filename: controllers/ForgotPassword.php Line Number: 14 Backtrace: File: C:\xampp\htdocs\Telkom\application\controllers\ForgotPassword.php Line: 14 Function: _error_handler File: C:\xampp\htdocs\Telkom\index.php Line: 315 Function: require_once

Here's my controller

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class ForgotPassword extends CI_Controller {

    public function __construct()
    {
        parent::__construct();
        $this->load->model('m_forgotpassword');      
    }

    public function FormEditPassword($id_user)
    {
        $data['akun']=$this->m_forgotpassword->get_data_selected($id_user)->result();
        $this->load->view("forgotpassword", $data);
    }

    public function AksiEditPassword()
    {

        $this->m_forgotpassword->EditDataPasword();
        redirect(base_url('index.php/login'));
    }

}

Here's my model

<?php
/**
* 
*/
class m_forgotpassword extends CI_Model
{

    function EditDataPassword()
    {       
      $data = array(
                    'email' => $this->input->post("email"),
                    'password' => $this->input->post("password"),
                    );
      $this->db->where("id_user",$this->input->post("id_user"));
      $this->db->update("akun",$data);
    }

    function get_data_selected($id_user)
    {
        $this->db->where("id_user",$id_user);
        return $this->db->get("akun");
    }

}
?>

And here's my view

    <head>
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
    <link href="<?php echo base_url() ?>assets/css/login.css" rel="stylesheet">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
    <link rel="icon" type="image/png" href="<?php echo base_url() ?>assets/img/icon.png">
    <title>TELKOM - PT. Telekomunikasi Indonesia Tbk</title>
</head>

<body>
    <div class="main">
        <div class="container">
        <center>
            <div class="middle">
                <div id="login">
                    <?php
                        echo form_open_multipart("forgotpassword/AksiEditPassword", array("class"=>"form-horizontal"));
                        foreach ($akun as $a) {        
                            echo form_input(array("name"  => "email",
                                                  "value" => $a->email,
                                                  "class" => "form-control",
                                                  "placeholder" => "Email",
                                                  "type"  => "text"));
                            echo form_input(array("name"  => "password",
                                                  "value" => $a->password,
                                                  "class" => "form-control",
                                                  "placeholder" => "New Password",
                                                  "type"  => "text"));
                            echo form_input(array("name"  => "id_user",                             
                                                  "value" => $a->id_user,                             
                                                  "type"  => "hidden"));
                            echo form_input(array("class" => "btn btn-success",
                                                  "type"  => "submit",
                                                  "value" => "Submit"));
                          }
                    ?>
                    <span style="width:50%; text-align:right;  display: inline-block;"><a class="small-text" href="<?php echo base_url('index.php/login')?>">Cancel</a></span>
                </div> <!-- end login -->
                <div class="logo">
                    <img src="<?php echo base_url('assets/img/logo2.png')?>" style="margin-left: 50px; width: 300px; height: 150px;">
                    <div class="clearfix"></div>
                </div>
            </div>
        </center>
        </div>
    </div>
</body>
2
Just a tip: your naming your file and class wrong the first letter only should be upper case on class and filenames the rest lower case. Explained here codeigniter.com/user_guide/general/styleguide.html#file-namingMr. ED
And on the controller function try FormEditPassword($id_user = '')Mr. ED
your $id_user is the required argument but its missing tats the error change it to public function FormEditPassword($id_user = NULL)Arun pandian M
@wolfgang1983 I've change my naming file and class but nothing changeUlfah Putri
@UlfahPutri it was just a tipMr. ED

2 Answers

1
votes

url you are calling should pass argument($user_id) for eg:

http://localhost/myProject/ForgotPassword/FormEditPassword/2

2 represents your $id_user parameter

Controller:

public function FormEditPassword($id_user = NULL)   // if no data is passed the variable is set to null 
{
  if($id_user){               
    $data['akun']=$this->m_forgotpassword->get_data_selected($id_user)->result();
  }
        $this->load->view("forgotpassword", $data);
}

View :

<?php
                        echo form_open_multipart("forgotpassword/AksiEditPassword", array("class"=>"form-horizontal")); 
if($akun){ // always check value exist before assigning any variable
                        foreach ($akun as $a) {        
                            echo form_input(array("name"  => "email",
                                                  "value" => $a->email,
                                                  "class" => "form-control",
                                                  "placeholder" => "Email",
                                                  "type"  => "text"));
                            echo form_input(array("name"  => "password",
                                                  "value" => $a->password,
                                                  "class" => "form-control",
                                                  "placeholder" => "New Password",
                                                  "type"  => "text"));
                            echo form_input(array("name"  => "id_user",                             
                                                  "value" => $a->id_user,                             
                                                  "type"  => "hidden"));
                            echo form_input(array("class" => "btn btn-success",
                                                  "type"  => "submit",
                                                  "value" => "Submit"));
                          }
}else{
echo "Value is empty" ;
}
0
votes

In your controller you need to pass data to model function like describe below.

public function AksiEditPassword()
{
    $param = $this->input->post();
    $this->m_forgotpassword->EditDataPasword($param);
    redirect(base_url('index.php/login'));
}

And in your model function will look like describe below.

function EditDataPassword($param = null)
{       
  $updData['email'] = $param['email'];
  $updData['password'] = $param['password'];
  $this->db->where("id_user",$param['id_user']);
  $this->db->update("akun",$updData);
}

Let me know if it not works.