CodeIgniter Forums
Data is inserting Repeatedely when i click refresh. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Data is inserting Repeatedely when i click refresh. (/showthread.php?tid=18191)



Data is inserting Repeatedely when i click refresh. - El Forum - 04-28-2009

[eluser]Dinesh Viswanath[/eluser]
Hello All,

I'm new to CI, But learning as quick as possible. Now, I'm developing an News Board Application. In this i'll add news & update it.

Code:
class NewsController extends Controller {
    function NewsController()
    {
    parent::Controller();    
    }
    function index()
    {
    $this->load->model('newsmodel');
    $data['news_collection']=$this->newsmodel->getNewsIndex();
    $this->load->view('svs_view',$data);
    }
function addnews()
    {
    $title=$this->input->post('vTitle');
    $name=$this->input->post('vContent');
    $date=$this->input->post('vDate');
    $this->load->model('newsmodel');
    $data['rows_affected']=$this->newsmodel->addNews($title,$name,$date);    
    self::index();
    
    }
}



For adding News,
My URL will looks like - <b>http://localhost/index.php/newcontroller/addnews</b>. After successfully adding Data to the Database I’m calling the Index () function. But URL is remaining same as <b>http://localhost/index.php/newcontroller/addnews. <br>Once when i Press "REFRESH" Button Data is Repeatedly Inserting into database. I wanted to have U</b>RL looks like <b>http://localhost/index.php/newscontroller</b> So that Data won’t be inserted with out necessary.
Pls tell some way to control this Refresh problem.


Data is inserting Repeatedely when i click refresh. - El Forum - 04-28-2009

[eluser]cideveloper[/eluser]
Instead of using

Code:
self::index();

why dont you use

Code:
redirect('/newscontroller/', 'refresh');

as long as nothing is being written to the browser this will work. See the link below

http://ellislab.com/codeigniter/user-guide/helpers/url_helper.html


Data is inserting Repeatedely when i click refresh. - El Forum - 04-28-2009

[eluser]Thorpe Obazee[/eluser]
You could use sessions to 'remember' that the same user(or anything) has inserted data then prevent it.


Data is inserting Repeatedely when i click refresh. - El Forum - 04-28-2009

[eluser]slowgary[/eluser]
Why not just stop clicking refresh? ;-)


Data is inserting Repeatedely when i click refresh. - El Forum - 04-28-2009

[eluser]Thorpe Obazee[/eluser]
[quote author="slowgary" date="1240991746"]Why not just stop clicking refresh? ;-)[/quote]

Prevention is better than cure? Smile


Data is inserting Repeatedely when i click refresh. - El Forum - 04-28-2009

[eluser]Dinesh Viswanath[/eluser]
A perfect Design should forgive even when user commits mistake unknowingly. @bargainph well said...


Data is inserting Repeatedely when i click refresh. - El Forum - 04-29-2009

[eluser]Zeeshan Rasool[/eluser]
Please read this

Redirection Problem