-4

I need to display an id number from "kategori_barang" table. When I submitted the code, I get an error message which says "trying to access array offset on the value of type null". Somebody can figure this out? Thanks for the help.

//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>
6
  • Where $record is declare? Commented Jan 29, 2021 at 11:10
  • I've declare from a controller part : Commented Jan 29, 2021 at 11:36
  • function edit() { if(isset($_POST['submit'])){ //proses kategori $this->model_kategori->post(); redirect('kategori'); } else{ $id = $this->uri->segment(3); echo $id; $data['record'] = $this->model_kategori->get_one($id)->row_array(); $this->load->view('kategori/form_edit', $data); } } Commented Jan 29, 2021 at 11:38
  • And I have a model. Iam using codeigniter Commented Jan 29, 2021 at 11:39
  • function edit() { $data = array( 'nama_kategori'=> $this->input->update('kategori') ); $this->db->where('kategori_id', $this->input->post(id)); $this->db->update('kategori_id', $data); } Commented Jan 29, 2021 at 11:40

1 Answer 1

0

the error means that your $record array has no such key. either use

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

or dump the $record to logs to see what is inside like this

error_log( print_r($record, TRUE) );

and take it from there....it looks like your $record has nothing in it

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.