• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 433
  • Last Modified:

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);
    oci_execute($statement);
    }
}

Open in new window

0
wellso
Asked:
wellso
  • 4
  • 2
2 Solutions
 
Michael701Commented:
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') ...
0
 
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,
0
 
Michael701Commented:
try adding an

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

in the loop, see if it's issuing the insert twice. post results here.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
wellsoAuthor Commented:
INSERT INTO DOCSLINKS (LINK_ID, DOC_ID, ORDER_ID) VALUES (LINK_ID_SEQ.nextval, '1091' ,'AM12345')

It only seems to go round the loop once but inserts two records, it puzzles me how it only happens in IE
0
 
wellsoAuthor Commented:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Windows/Q_23791556.html

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.
0
 
wellsoAuthor Commented:
Thanks for the help, got it sorted in the end : pesky JavaScript handling in IE :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now