Welcome Guest, Not a member yet? Register   Sign In
Refresh duplicates records
#1

[eluser]Unknown[/eluser]
I'm new to codeigniter and am trying it out in a new project. Its a small cms.

I have a problem with records being added when I refresh the page.

1. I have a form with a textfield. I add text en then click submit.
2. The form links to a controller function which processes the information and adds it to the database. Then it runs the index function of the controller, thus loading a new view.

So far so good, but then...

3. Instead of the url in the new view being the index function, the url remains the function from from step 2. Thus, everytime I refresh the page a new record is added.

Is there a way to solve or work around this?
#2

[eluser]Krzemo[/eluser]
no code? adding some would help getting right answer fast Smile
one of the solutions could be adding redirect('controller_name') at the end of function from point 2 ...
#3

[eluser]Zack Kitzmiller[/eluser]
Show us the code.
#4

[eluser]jcavard[/eluser]
Show us the puppies!
#5

[eluser]Kinsbane[/eluser]
The problem is, you're calling the index function of the Controller - the browser is not making a new request or being redirected anywhere. When you refresh (not sure why you need to refresh anyway..) the browser is requesting the last requested URL - in this case, the controller that handles adding the data to the database.

As Cshamoh said, this would work:
Code:
<?php
$q = $this->db->query("INSERT INTO table SET foo = 'bar'");
redirect('your_controller', 'location');
?>




Theme © iAndrew 2016 - Forum software by © MyBB