• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Update Database Code Problems

#1
[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:
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>
&lt;input type="radio" name="banner_num" value="one" /&gt;One <br />
&lt;input type="radio" name="banner_num" value="two" /&gt;Two <br />
&lt;input type="radio" name="banner_num" value="three" /&gt;Three <br />

&lt;input type="radio" name="banner_num" value="four" /&gt;Four <br />
&lt;input type="submit" name="submitted" /&gt;
&lt;/form&gt;

&lt;form action="" method="post"&gt;
<h3>Title:</h3>
&lt;input type="text" name="title" value="&lt;?php echo $banner-&gt;title; ?&gt;" />
<h3>Description:</h3>
&lt;textarea name="desc" style="width: 400px; height: 200px; overflow: scroll;"&gt;&lt;?php echo $banner->description; ?&gt;&lt;/textarea&gt;
<h3>Image URL:</h3>
&lt;input type="text" name="image" value="&lt;?php echo $banner-&gt;image; ?&gt;" />
<br />
&lt;input type="hidden" name="id" value="&lt;?php echo $banner-&gt;id; ?&gt;" />
&lt;input type="submit" name="submitted_2" /&gt;
&lt;/form&gt;

Thanks!


Messages In This Thread
Update Database Code Problems - by El Forum - 06-13-2009, 07:24 PM
Update Database Code Problems - by El Forum - 06-13-2009, 07:35 PM
Update Database Code Problems - by El Forum - 06-13-2009, 07:49 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.