【问题标题】:How to fixed an error message : "trying to access array offset on value of type null." at a $record syntax? [duplicate]如何修复错误消息:“尝试访问 null 类型值的数组偏移量。”在 $record 语法? [复制]
【发布时间】:2021-01-29 11:07:17
【问题描述】:

我需要显示“kategori_barang”表中的 ID 号。当我提交代码时,我收到一条错误消息,上面写着“尝试访问 null 类型值的数组偏移量”。有人能解决这个问题吗?感谢您的帮助。

//the title
<h3>Form Edit Kategori</h3>

//syntax for open a controller 
<?php echo form_open('kategori/edit'); ?>
 
//list for display an id number
<input type="text" value="<?php echo $record['kategori_id'];?>" name="id">
<table border="1">
    <tr>
        <td>Nama Kategori</td>
        <td><input type="text" name="kategori" placeholder="kategori" 
                   value="<?php echo $record['nama_kategori'];?>"></td>
    </tr>
    <tr>
        <td colspan="2"><button type="submit" name="submit">Submit</button></td>
    </tr>
</table>
</html>

【问题讨论】:

  • $record 在哪里声明?
  • 我已经从控制器部分声明:
  • function edit() { if(isset($_POST['submit'])){ //散文分类 $this->model_kategori->post();重定向('类别'); } else{ $id = $this->uri->segment(3);回声 $id; $data['record'] = $this->model_kategori->get_one($id)->row_array(); $this->load->view('categori/form_edit', $data); } }
  • 我有一个模型。我正在使用 codeigniter
  • 函数编辑() { $data = array( 'nama_kategori'=> $this->input->update('kategori') ); $this->db->where('kategori_id', $this->input->post(id)); $this->db->update('kategori_id', $data); }

标签: php codeigniter


【解决方案1】:

错误意味着您的 $record 数组没有这样的键。 要么使用

isset($record['kategori_id']) ? $record['kategori_id'] : 0;

或将 $record 转储到日志中,看看里面是这样的

error_log( print_r($record, TRUE) );

然后从那里拿走它......看起来你的 $record 里面什么都没有

【讨论】:

    猜你喜欢
    • 2020-07-29
    • 1970-01-01
    • 2021-04-26
    • 2020-05-28
    • 2021-07-23
    • 1970-01-01
    相关资源
    最近更新 更多