06-13-2009, 07:24 PM
[eluser]Gwarrior[/eluser]
Hey guys and thanks in advance for taking a look!
I'm having trouble with this pretty simple script. I basically just want it to pull from a database, and populate a form (which it does fine), then have it where I can edit the data from that form and update the database upon submission.
The whole thing seems to work, with no errors anywhere, yet the database does NOT update when I submit the form.
Controller:
View:
Thanks!
Hey guys and thanks in advance for taking a look!
I'm having trouble with this pretty simple script. I basically just want it to pull from a database, and populate a form (which it does fine), then have it where I can edit the data from that form and update the database upon submission.
The whole thing seems to work, with no errors anywhere, yet the database does NOT update when I submit the form.
Controller:
Code:
<?php
class Edit extends Controller {
function Edit() {
parent::Controller();
$this->load->library('session');
$this->load->database();
}
function banners() {
if ($this->session->userdata('logged_in') == TRUE) {
$data['logged_in'] = $this->session->userdata('logged_in');
$query = $this->db->query('SELECT * FROM banners');
$data['banner'] = '';
if (@$_POST['banner_num'] == 'one') {
$data['banner'] = $query->row(1);
}
if (@$_POST['banner_num'] == 'two') {
$data['banner'] = $query->row(2);
}
if (isset($_POST['submitted_2'])) {
$id = $this->input->post('id');
$title = $this->input->post('title');
$desc = $this->input->post('desc');
$image = $this->input->post('image');
$query_2 = $this->db->query('UPDATE banners SET title = \'$title\', description = \'$desc\', image = \'$image\' WHERE id = \'$id\'');
}
$this->load->view('banners', $data);
} else {
$this->load->view('login');
}
}
}
?>
View:
Code:
<form action="" method="post">
<h3>Which Banner to Replace:</h3>
<input type="radio" name="banner_num" value="one" />One <br />
<input type="radio" name="banner_num" value="two" />Two <br />
<input type="radio" name="banner_num" value="three" />Three <br />
<input type="radio" name="banner_num" value="four" />Four <br />
<input type="submit" name="submitted" />
</form>
<form action="" method="post">
<h3>Title:</h3>
<input type="text" name="title" value="<?php echo $banner->title; ?>" />
<h3>Description:</h3>
<textarea name="desc" style="width: 400px; height: 200px; overflow: scroll;"><?php echo $banner->description; ?></textarea>
<h3>Image URL:</h3>
<input type="text" name="image" value="<?php echo $banner->image; ?>" />
<br />
<input type="hidden" name="id" value="<?php echo $banner->id; ?>" />
<input type="submit" name="submitted_2" />
</form>
Thanks!