编辑表单错误;代码点火器


Error in edit form; Codeigniter

我遇到了这个错误。

遇到 PHP 错误

严重性:通知

消息:未定义的属性:标准类::$fname

文件名:视图/view_editstud.php

行号:60

这是我的观点:

     <form method="post" action="<?php echo base_url();?>site/update_stud">
            <table>
                <?php foreach ($user->result() as $row) { ?>
                <tr>
                    <th scope="row">Enter your first name</th>
                    <td><input type="text" name="fname" size="20" value="<?php echo $row->fname; ?>" /></td>
                </tr>
                <tr>
                    <th scope="row">Enter your last name</th>
                    <td><input type="text" name="lname" size="20" value="<?php echo $row->lname; ?>" /></td>
                </tr>
                <tr>
                    <th scope="row">Enter your contact number</th>
                    <td><input type="text" name="contact" size="20" value="<?php echo $row->contact; ?>" /></td>
                </tr>
                <tr>
                    <th scope="row">Enter your address</th>
                    <td><textarea name="address" rows="5" cols="20"><?php echo $row->address; ?></textarea></td>
                </tr>
                <tr>
                    <td><input type="hidden" name="id" value="<?php echo $row->id; ?>" />
                        <input type="submit" name="submit" value="Update" /></td>
                </tr>
                <?php } ?>
            </table>

这是我的控制器:

 public function edit($id) {
    $this->load->model('stud_model');
    $data['title'] = "edit";
    $data['user'] = $this->stud_model->getById($id);
    $this->load->view('view_editstud', $data);
}

这是我的模型:

 public function getById($id) {
    $query = $this->db->get_where('students', array('ID'=>$id));
    return $query;
}

谁能帮我解决这个问题?

print($row) 

并检查$fname索引在数组中可用或不可用,此问题是由如果只有此索引不可用引起的