Welcome Guest, Not a member yet? Register   Sign In
Simple insert being inserted twice
#1

[eluser]erikdrums[/eluser]
I might be overlooking something terribly obvious, but if I run the following code directly in a controller:
Code:
function advertising() {
    $project_id = $this->input->get('project_id');
    $this->db->insert('ads', array('headline' => 'headline', 'project_id' => $project_id));
  }
Two entries are made in the db??? What would cause this to be run twice?
Code:
echo $this->db->last_query();
only displays one insert also.
#2

[eluser]WanWizard[/eluser]
last_query() will always shows one query (namely the last one executed).

You could activate the profiler to see all queries executed.

If you see only one there as well, it could be that your page is requested twice (this can happen if you use the default rewrite rules and one of your assets, or a favicon, is missing). To see if this the case, check your CI and/or server logfiles.
#3

[eluser]erikdrums[/eluser]
Thank you for a very useful reply. All other inserts seemed to work so it twisted my head a bit.
It turnes out I had a html validation extension running for chrome that made the double request for only some functions.
I will be better suited to debug similar issues in the future because of your reply.

Thank you! Smile
#4

[eluser]phpfresher[/eluser]
May be your method adevertesing() is executed twice . Once before submit and after you click the submit button.
Before you submit why don't you add this type of code like
Code:
if($this->input->post('submit')){
       submit the data
}




Theme © iAndrew 2016 - Forum software by © MyBB