【问题标题】:Error in edit form; Codeigniter编辑表格错误;代码点火器
【发布时间】:2014-11-15 11:57:53
【问题描述】:

我遇到了这个错误。

遇到了 PHP 错误

严重性:通知

消息:未定义的属性:stdClass::$fname

文件名:views/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 索引是否可用这个问题是由如果只有这个索引不可用引起的

标签: php codeigniter edit


【解决方案1】:
print($row) 

并检查 $fname 索引在数组中是否可用,如果只有此索引不可用,则会导致此问题

【讨论】:

  • 把它放在视图后面检查 result() as $row) { ?>
  • 遇到 PHP 错误严重性:4096 消息:stdClass 类的对象无法转换为字符串文件名:views/view_editstud.php 行号:58
  • 把这个print_r($row);exit; before &lt;?php foreach ($user-&gt;result() as $row) { ?&gt;
猜你喜欢
  • 2016-03-15
  • 2011-09-27
  • 2016-01-13
  • 2018-11-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多