Welcome Guest, Not a member yet? Register   Sign In
Data is inserting Repeatedely when i click refresh.
#1

[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.
#2

[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-gui...elper.html
#3

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

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

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

Prevention is better than cure? Smile
#6

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

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

Redirection Problem




Theme © iAndrew 2016 - Forum software by © MyBB