PHP and Internet Explorer - foreach loop making duplicate entrys

Hi there,

Having problems with IE inserting duplicate entrys into a database from an array of checkboxes in the $_POST header. It only happens on IE and not Firefox and I am completely stumped as to why? Can any shed any light on this?
if($_POST['query']=="add" && count($_POST['rep']) >= 1){
  foreach($_POST['rep'] as $value){
    $insert = "INSERT INTO DOCSLINKS (LINK_ID, DOC_ID, ORDER_ID) VALUES (LINK_ID_SEQ.nextval, '$value' ,'$am')";
    $statement = oci_parse($connect,$insert);

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

well first take a look at the array

$my_array = $_POST['rep'];
print_r ($my_array);

you might have to see if the checkbox is 'ON'

foreach($_POST['rep'] as $value=>$state)
  if ($state=='ON') ...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
wellsoAuthor Commented:
i have print_r the array, each check box holds a primary key value (doc_id) that I am adding to the database. print_r shows only 1 entry per ticked checkbox but the loop inserts 2 records in IE but works fine in Firefox,
try adding an

echo $insert ."<br />\n";

in the loop, see if it's issuing the insert twice. post results here.
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

wellsoAuthor Commented:

It only seems to go round the loop once but inserts two records, it puzzles me how it only happens in IE
wellsoAuthor Commented:

Found out the problem, turns out Javascript was submitting the form twice. I have various buttons on the form to perform different functions which trigger onclick events in JavaScript, one of which is submit(); the input type was still set to submit on the offending button leading to dual submissions of the form, I presume Firefox must have catched this and only submitted once, good job I am not designing an eccommerce credit card submission system hehe. Thanks for the help all the same.
wellsoAuthor Commented:
Thanks for the help, got it sorted in the end : pesky JavaScript handling in IE :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.