Home > Artikel, Pemprograman, web 3D ws > Edit Data Database dengan CodeIgniter

Edit Data Database dengan CodeIgniter

Setelah pada materi sebelumnya belajar seputar insert, delete dan update, sekarang saatnya kita belajar Edit Data Database dengan Framework CodeIgniter.Untuk sintak edit disini kita hanya perlu mengubah sedikit sintak insert Data. Berikut cuplikannya :

Controller

Tambahkan method berikut :


public function edit($id="")
{
$this->load->library('form_validation');
$this->form_validation->set_rules('title','Title','required');
$this->form_validation->set_rules('content','Content','required');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('view_edit');
}
else
{
$a = $this->input->post('title');
$b = $this->input->post('content');
$this->load->view('view_edit');
$this->ModelNews->edit($id,$a,$b);
redirect('Octav');
}
}

Model

Berikut model dalam database :


public function edit($id,$title,$content)
{
$q="update news set title='$title',content='$content' where id='$id'";
return $this->db->query($q);  //db->query() merupakan pengambilan query
}

View


<?php echo validation_errors(); ?>
<?php echo form_open(); ?>
<h5>Title</h5>
<form>
<input type="text" name="title" value="<?php echo set_value('title');?>" size="50" />
<h5>Content</h5>
<textarea name="content" cols="50" value="<?php echo set_value('content');?>"></textarea>
<br>
<div><input type="submit" value="Submit" /></div>
</form>

  1. August 6, 2012 at 5:58 am

    keren mas octav…
    silahkan datangi kampung saya di fromlombok.wordpress.com / pelajar-mania.blogspot.com

  2. December 6, 2012 at 2:54 am

    makasih mas octav , sangat bermanfaat sekali bagi saya🙂

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s