Welcome Guest, Not a member yet? Register   Sign In
refresh the page after clicking the button
#14

[eluser]bluepicaso[/eluser]
hello people..a problem im facing is related to the refreshing of the page.i haven't worked on CI before this is my first ever project most of which has to be completed by tomorrow to show to client..

The view submits the value to the controller, the controller passes it to the model.
The model saves it into the database....
the controller then redirects to the same view from which it all started...

But on refreshing the page the value still gets into the database...i dont want this.. is there a way to clear these post values....
below is the code....

View named admin_insert

Code:
<?php echo $sub;?>
                <?php echo form_open("insert/main_cat")?>
                    <table>
                        <tr>
                            <td>
                                Main Category
                            </td>
                            <td>
                                &lt;input type="text" name="cat"&gt;
                            </td>
                        </tr>
                        <tr>
                            <td>
                                &lt;input type="submit" value="Save"&gt;
                            </td>
                        </tr>
                    </table>
                &lt;?php form_close();?&gt;

controller named insert

Code:
&lt;?php
class Insert extends Controller
{
    function Insert()
    {
        parent::Controller();
    }
    function main_cat()
    {
        $cat = $this->input->post('cat');
        $this->load->model('insertmodel');
        $data['sub'] = $this->insertmodel->setCat($cat);
        if($data['sub'] == 1)
        {
            unset($_POST);
            $this->load->view('admin_insert', $data);
        }
        else
        {
           //--------data not inserted------------
           echo "Oops data is not inserted<br> Please go back and resubmit <br> OR <br> Try refreshing the page";
        }
        
    }
}
?&gt;
Model named insertmodel

Code:
&lt;?php
class insertModel extends Model
    {
    function insertModel()
    {
        parent::Model();
    }
        function setCat($a)
        {
            //$b = md5($b);
            $x = $this->db->query("insert into main (name) values ('$a')");
        return $x;
    }
    }
?&gt;


Messages In This Thread
refresh the page after clicking the button - by El Forum - 08-14-2009, 04:36 AM
refresh the page after clicking the button - by El Forum - 08-14-2009, 06:14 AM
refresh the page after clicking the button - by El Forum - 08-16-2009, 11:32 PM
refresh the page after clicking the button - by El Forum - 08-16-2009, 11:35 PM
refresh the page after clicking the button - by El Forum - 08-17-2009, 12:31 AM
refresh the page after clicking the button - by El Forum - 08-17-2009, 12:38 AM
refresh the page after clicking the button - by El Forum - 08-17-2009, 12:40 AM
refresh the page after clicking the button - by El Forum - 08-17-2009, 12:46 AM
refresh the page after clicking the button - by El Forum - 08-17-2009, 12:52 AM
refresh the page after clicking the button - by El Forum - 08-17-2009, 01:03 AM
refresh the page after clicking the button - by El Forum - 08-17-2009, 01:09 AM
refresh the page after clicking the button - by El Forum - 08-17-2009, 02:29 AM
refresh the page after clicking the button - by El Forum - 08-17-2009, 03:24 AM
refresh the page after clicking the button - by El Forum - 08-18-2009, 06:24 AM



Theme © iAndrew 2016 - Forum software by © MyBB