Page 1 of 1

IE executing twice INSERT STATEMENT on i-frame

Posted: Wed Sep 17, 2008 11:30 am
by Jaxolotl
Hi everyone, i made some research on the forum and Google but did not find a solution for this problem.

to add some properties to a record (call it product) i use an iframe containing the list of properties and the insertNew form.
Running on Firefox, Opera, Safari it does things right, but IE (explorer) runs the insert query twice.

I firts i check if the relationship product<=>attachement already exists.
then i make some mandatory values check
then if no error exists i run the query.

If i turn the relationship product<=>attachement check off the script insert the record twice, if i turn it on the script inserts the record once and then prompt the "already exists" warning.
I tried to redirect after the insert success witch headers('Location: xxxxxx ') but the problem persists

function req() is a function retrieving and returning $_REQUEST data cleaning it up from sqlInjection
sql_select() is the sql abstraction layer (I'm using persistent connections but the problem remains with non persistent too)

Code: Select all

 
  if(array_key_exists("create_ok",$_POST)){
 
    $query ="SELECT `rowid`,`related_attachement`,`parent_product_id`
    FROM `products_related_information`
    WHERE `parent_product_id` = '".RELATED_PARENT_PRODUCT_ID."'
    AND `related_attachement` = '".process_plain_text(strip_default_folders(req("related_attachement","POST", $sanitise = false)))."'
    ";
    sql_select($query,$results);
 
        if(mysql_num_rows($results)>0){
      $error_exists = true;
      echo  "".translate("exclaim_image")."<strong><span class=\"red\">\" The selected relationship already exits on this database. !!\"</span> ".translate("ammend").".</strong><br><br>";
    }
    
    elseif(!trim(req("related_attachement","POST", $sanitise = false))){
      $error_exists = true;
      echo  "".translate("exclaim_image")." <strong><span class=\"red\">\" A Related Attachement MUST be selcted. !!\"</span> ".translate("ammend").".</strong><br><br>";
    }
 
        elseif((trim(req("related_attachement","POST", $sanitise = false)))&&(!this_file_exists(req("related_attachement","POST", $sanitise = false),"../".DOCUMENTS_FOLDER))){
            $error_exists = true;
            echo  "".translate("exclaim_image")." <strong><span class=\"red\">\" The attachement file doesn't exists !!\"</span> ".translate("ammend").".</strong><br><br>";
        }
 
        elseif((trim(req("related_attachement","POST", $sanitise = false)))&&(!trim(req("related_attachement_title","POST", $sanitise = false)))){
            $error_exists = true;
            echo  "".translate("exclaim_image")." <strong><span class=\"red\">\" A Title for the attachement file in mandatory !!\"</span> ".translate("ammend").".</strong><br><br>";
        }
        
 
    else{
      $error_exists = false;
      
 
      //////start query
 
      $create_att_query = "INSERT IGNORE INTO `products_related_information`
      (
      `parent_product_id`,
      `related_attachement`,
      `related_attachement_title`,
      `related_attachement_language_id`,
      `update_date`,
      `last_editor`
      )
 
      VALUES
 
      (
      '".RELATED_PARENT_PRODUCT_ID."',
      '".process_plain_text(strip_default_folders(req("related_attachement","POST", $sanitise = false)))."',
      '".process_plain_text(req("related_attachement_title","POST", $sanitise = false))."',
      '".process_plain_text(req("language_id","POST", $sanitise = false))."',
      NOW(),
      '".$_SESSION[LOCAL_IDENTIFIER.'_CURRENT_ADMINISTRATOR_ID']."'
      )";
 
      if(sql_select($create_att_query,$create_att_results)){
        echo "<strong class=\"green\">".translate("attachement")." <span class=\"grey_strong\">".stripslashes(process_plain_text(strip_default_folders(req("related_attachement","POST", $sanitise = false))))."</span> ".translate("created_successfully").".</strong><br><br>";
      }
      else{
        echo "<strong class=\"red\">ERROR-Database error</strong><br>".$_SESSION[LOCAL_IDENTIFIER.'_DB_ERRORS']."<br><br>";
      }
 
    }
 
  }
 

Re: IE executing twice INSERT STATEMENT on i-frame

Posted: Wed Sep 17, 2008 11:47 am
by Jaxolotl
Am I dreaming???
I change the submit button (i was trying to make things standard)

Code: Select all

 
<input name="create_ok" value="Confirm creation" type="hidden" >
<input name="create_ok_button" title="Confirm creation" value="Confirm creation" type="image" OnClick="submit();" src="immagini/round_ok.gif"> 
 
with

Code: Select all

 
<input name="create_ok" value="Confirm creation" type="submit"  class="green_button">      
 
and the problem was solved 8O

can anyone explains me why IE submits post twice when using an input type image? Maybe I miss that lesson :oops:

Re: IE executing twice INSERT STATEMENT on i-frame

Posted: Wed Sep 17, 2008 4:45 pm
by thinsoldier
I have no idea. All the browsers do lots of weird crap.
For instance, I had a script that updated the number_of_times_viewed field on the record being viewed. Every page load that number would increase by 2 instead of 1. Turns out I had an <img src="" alt=""> (an empty image tag) on the page.
Loading a page with an empty <img> makes the browser load the url of the page AGAIN in an attempt to use it as the <img> contents!

Also, ALWAYS exit; after using header("Location: ");
Sure your browser will navigate to another location but the original script is still executing away on the server long after your browser has left that page.

Re: IE executing twice INSERT STATEMENT on i-frame

Posted: Wed Sep 17, 2008 6:31 pm
by josh
If you use a custom 404 handling page in your application and you include a resource that doesn't exist, sometimes your code will get run twice as apache will serve your applications 404 "page" even if the requested resource type was an image. So if you have a file in your framework that updates a web stats log for instance, and this file is also included on your 404 page, then any broken resources will overinflate your log file. Keep in mind browsers automatically request resources all the time that you didn't neccessarily plan for, for instance the favicon feature. Browsers don't really do "wierd crap", everything has a reason ( well maybe aside from IE )

Re: IE executing twice INSERT STATEMENT on i-frame

Posted: Thu Sep 18, 2008 5:25 pm
by thinsoldier
well, a lot of those "reasons" don't seem to be documented anywhere.

For instance, the css box model says overflow:hidden makes a container clip any content outside of the visible area yet if you put overflow:hidden on a <fieldset> you can still see the entire <legend> even though it's positioned so as to place the top half of the <legend> outside of the area of the <fieldset>. It goes agains all the documented rules!

Re: IE executing twice INSERT STATEMENT on i-frame

Posted: Thu Sep 18, 2008 5:35 pm
by josh
Well their reasoning is that they interpreted those documents differently then the other browser manufacturers, is that true? Well technically but they probably had other motivations for doing it.

I'm just saying if you don't understand something, even if it still works.. often its better to try and understand it.. often times nominal issues can be indicative of a larger problem in your design.

Re: IE executing twice INSERT STATEMENT on i-frame

Posted: Thu May 28, 2009 3:51 am
by grotfl
For the future searchers - I think the problem could be that nothing is explicitly returned in onclick="". For instance:
... onclick="submit(); return false;" ...

You would have to try it though.

I am having a similar issue, but in my case I am using onsubmit="" on <form> tag:
<form name="formData" action="" enctype="multipart/form-data" method="post" onsubmit="document.formData.submit(); return true;">
Everything works in all other browsers and in most cases in IE too - but on some servers and/or IE versions it double posts. Go figure.

But this is not meant as a question, just wanted to point to a return bit in the original post.