0

Can anyone help me understand this code and why it has an error appearing?

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: plain_pass

Filename: views/editusers.php

Line Number: 59

Line 59:

<td> 
<input type="password" name="password" value="<?php echo $plain_pass; ?>"> </td>

controllers/Cpages.php

 public function editusers() { 


    $user_id = $this->uri->segment(3);

    $data['users'] = $this->Mpages->call_point_users($user_id);

    foreach($users as $users_item) {            
        $encrypt_pass = $users_item['password'];            
        $plain_pass = $this->encrypt->decode($encrypt_pass);            
    }

    $this->load->view('editusers', $data, $plain_pass); 


}

views/editusers.php

                <div class="widget-box">
                    <div class="widget-title"><h5>Users</h5></div>
                    <div class="widget-content">

                    <?php echo form_open('cpages/editusersdb'); ?>                      
                    <table border="0" style="width: 100%; height: 90px;">
                        <tr>
                            <td>NAME</td>
                            <td><input type="text" name="fname" value="<?php echo $users_item['username']; ?>"></td>
                        </tr>
                        <tr>
                            <td>EMAIL</td>
                            <td><input type="text" name="fname" value="<?php echo $users_item['email']; ?>"></td>
                        </tr>
                        <tr>
                            <td>PASSWORD</td>
                            <td><input type="password" name="password" value="<?php echo $plain_pass; ?>"></td>
                        </tr>
                        <tr>
                            <td>ROLE</td>
                            <td>
                            <select>
                            <optgroup>
                            <option value="Administrator">Administrator</option>
                            <option value="Manager">Manager</option>
                            </optgroup>
                            </select>
                            </td>
                        </tr>
                        <tr>
                            <td></td>
                            <td><input type="submit" class="edit" name="submit" value="SUBMIT"></td>
                        </tr>                           
                    </table>            
                    </div>

                    <?php endforeach; ?>
1
  • Don't forget when a answer has worked for you to accept it. Commented Dec 6, 2016 at 23:55

2 Answers 2

2

Put $plain_pass into your data array.

public function editusers() { 

    $user_id = $this->uri->segment(3);

    $data['users'] = $this->Mpages->call_point_users($user_id);

    foreach($users as $users_item) {            
        $encrypt_pass = $users_item['password'];            
        $plain_pass = $this->encrypt->decode($encrypt_pass);            
    }

    $data['plain_pass'] = $plain_pass; 

    $this->load->view('editusers', $data); 

}
Sign up to request clarification or add additional context in comments.

Comments

1

The best way I find

 $data['users'] = array();

 $results = $this->Mpages->call_point_users($user_id);

 if (isset($results)) {

 foreach ($results as $result) {
    $data['users'][] = array(
       'email' => $result['email'],
       'username' => $result['username'],
       'encrypt_pass' => $result['password'], 
       'plain_pass' => $this->encrypt->decode($result['encrypt_pass'])
    );
 }

 }

 $this->load->view('someview', $data);

Don't have two types of pass words only have one. Also codeigniter encrypt is not code still for passwords because it can be decrypted, Instead use some like

http://php.net/manual/en/function.password-hash.php and for verify http://php.net/manual/en/function.password-verify.php varchar 255

View

<table>
<thead>

</thead>
<tbody>
<?php foreach ($users as $user) {?>
<tr>
<td>NAME</td>
<td><input type="text" name="username" value="<?php echo $user['username']; ?>"></td>
</tr>
<tr>
<td>EMAIL</td>
<td><input type="text" name="email" value="<?php echo $user['email']; ?>"></td>
</tr>
<tr>
<td>PASSWORD</td>
<td><input type="password" name="password" value="<?php echo $user['plain_pass']; ?>"></td>
</tr>
<?php }?>
</tbody>
</table>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.