title: Codeigniter : How to get ID from URL
body: <p>I want to ask, how to post ID to database from URL, I can see this ID in the last url.
  my Url :</p>
  
  <pre><code>http://localhost/rekammedis/index.php/pasien/tambah_rm/3
  </code></pre>
  
  <p>I'm using uri to get $id_pasien value but when I post to database this value is null/empty not posted.</p>
  
  <p>my model :</p>
  
  <pre><code>function tambahrm($id)
  {
      $this-&gt;load-&gt;helper('url');
      $username = trim($this-&gt;session-&gt;userdata('id'));
      $id_pasien = $this-&gt;uri-&gt;segment(3);
      $data = array(
          'tgl_berobat' =&gt; $this-&gt;input-&gt;post('tgl_berobat'),
          'anamnesa' =&gt; $this-&gt;input-&gt;post('anamnesa'),
          'diagnosa' =&gt; $this-&gt;input-&gt;post('diagnosa'),
          'therapi' =&gt; $this-&gt;input-&gt;post('therapi'),
          'keterangan' =&gt; $this-&gt;input-&gt;post('keterangan'),
          'id_user' =&gt; $username,
          'id_pasien' =&gt; $id_pasien,
      );
  
      if ($id == 0) {
          return $this-&gt;db-&gt;insert('tbl_riwayat', $data);
      } else {
          $this-&gt;db-&gt;where('id', $id);
          return $this-&gt;db-&gt;update('tbl_riwayat', $data);
      }
  }
  </code></pre>
  
  <p>here is result :
  <a href="https://i.stack.imgur.com/XdmFf.png" rel="nofollow noreferrer">Id_pasien remains unfilled.</a></p>