[eluser]anyamanggar[/eluser]
please help me, i am nubie,
i want to update my database, and my script doesnt work,
this is my controller
Code: function edit($id = 0) {
$this->check_logged_in();
$this->load->model('news_model');
if ($id == null) {
$id = $this->input->post('id');
}
$this->form_validation->set_rules('title', 'title', 'required');
$this->form_validation->set_rules('slug', 'slug', 'required');
$this->form_validation->set_rules('intro', 'intro', 'required');
$this->form_validation->set_rules('text', 'text', 'required');
$this->form_validation->set_error_delimiters('', '<br/>');
if ($this->form_validation->run() == TRUE) {
$this->news_model->update($id);
redirect('news_admin');
}
$data['page'] = $this->news_model->findById($id);
$data['content'] = 'editnews_view';
$this->load->view('admin/editnews_view', $data);
}
news_model.php
Code: function findById($id) {
$query = $this->db->get_where('news', array('id' => $id));
return $query->row_array();
}
function update($id) {
$data = array(
' title' => $this->input->post('title'),
'slug' => $this->input->post('slug'),
'intro' => $this->input->post('intro'),
'text' => $this->input->post('text'),
);
$this->db->where('id', $id);
$this->db->update('news', array('id' => $id));
}
editnews_view.php
Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Administrator | PT. Mitra Arta Semesta | Engineering and Contraction Company</title>
<link rel="stylesheet" href="<? echo base_url(); ?>script/admin.css" type="text/css">
<!-- ini untuk tinyeditor -->
[removed][removed]
</head>
<body>
<?php $this->load->view('admin/header_view'); ?>
<h1 class="submenuadmin">Saat ini anda berada di : <strong>Main > Add News</strong></h1>
<div id="addnewsadmin">
<? echo form_open('edit'); ?>
<?php echo form_hidden('id', $page['id']); ?>
<table width="800" border="0" cellspacing="1" cellpadding="1">
<tr>
<td align="left" valign="top">Judul Berita</td>
<td align="left" valign="top">
<?php echo form_input(array('name' => 'title', 'value' => set_value('title', isset($page['title']) ? $page['title'] : ''))); ?>
</td>
</tr>
<tr>
<td align="left" valign="top">SEO URL</td>
<td align="left" valign="top"> <?php echo form_input(array('name' => 'slug', 'value' => set_value('slug', isset($page['slug']) ? $page['slug'] : ''))); ?><br />
<strong><em>Form input SEO URL diisi dengan format spasi diganti dengan tanda . (titik) agar URL Friendly</em></strong></td>
</tr>
<tr>
<td align="left" valign="top">Intro</td>
<td align="left" valign="top">
<?php echo form_input(array('name' => 'intro', 'value' => set_value('intro', isset($page['intro']) ? $page['intro'] : ''))); ?>
</td>
</tr>
<tr>
<td align="left" valign="top">ISi Berita</td>
<td align="left" valign="top"><?php echo form_textarea(array('name' => 'text', 'value' => set_value('text', isset($page['text']) ? $page['title'] : ''))); ?>
[removed]
//<![CDATA[
// This call can be placed at any point after the
// <textarea>, or inside a <head>[removed] in a
// window.onload event handler.
// Replace the <textarea id="editor"> with an CKEditor
// instance, using default configurations.
CKEDITOR.replace( 'text' );
//]]>
[removed]</td>
</tr>
<tr>
<td align="left" valign="top"> </td>
<td valign="top"><? echo form_submit('mysubmit','Submit Berita'); ?></td>
</tr>
</table>
<? echo form_close(); ?>
</div>
<br /><br />
</body>
</html>
please help me, i am stuck for this problem, and many thanks
[eluser]njkt[/eluser]
Code: function update($id) {
$data = array(
' title' => $this->input->post('title'),
'slug' => $this->input->post('slug'),
'intro' => $this->input->post('intro'),
'text' => $this->input->post('text'),
);
$this->db->where('id', $id);
[b] $this->db->update('news', array('id' => $id));[/b]
}
This function doesn't actually update, you forgot to pass $data.
[eluser]anyamanggar[/eluser]
so?, where i have to change?
[eluser]nagata[/eluser]
Code: function update($id) {
$data = array(
' title' => $this->input->post('title'),
'slug' => $this->input->post('slug'),
'intro' => $this->input->post('intro'),
'text' => $this->input->post('text'),
);
$this->db->where('id', $id);
$this->db->update('news', $data);
}
bases on some of the code i had for my application, this should work for you
[eluser]anyamanggar[/eluser]
[quote author="nagata" date="1339744877"] Code: function update($id) {
$data = array(
' title' => $this->input->post('title'),
'slug' => $this->input->post('slug'),
'intro' => $this->input->post('intro'),
'text' => $this->input->post('text'),
);
$this->db->where('id', $id);
$this->db->update('news', $data);
}
bases on some of the code i had for my application, this should work for you
[/quote]
erorr like this, after i used your code
Code: Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'slug` = 'uuuuu', `intro` = 'uuuuu', `text` = '
\r\n uuuuu
\r\n' WHERE `id` ' at line 1
UPDATE `news` SET ` title = 'uuuuuhhh', `slug` = 'uuuuu', `intro` = 'uuuuu', `text` = '
\r\n uuuuu
\r\n' WHERE `id` = '28'
Filename: C:\AppServ\www\mitra\system\database\DB_driver.php
Line Number: 330
[eluser]Unknown[/eluser]
thank you for try to helping me, this code finally work by me..
Code: function update(){
$this->load->database();
$data = array(
'title'=>$this->input->post('title'),
'slug'=>$this->input->post('slug'),
'intro'=>$this->input->post('intro'),
'text'=>$this->input->post('text'),);
$this->db->where('id',$this->input->post('id'));
$this->db->update('news',$data);
}
|