?
Solved

PHP and Internet Explorer - foreach loop making duplicate entrys

Posted on 2008-11-10
6
Medium Priority
?
429 Views
Last Modified: 2013-12-13
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
Comment
Question by:wellso
  • 4
  • 2
6 Comments
 
LVL 19

Accepted Solution

by:
Michael701 earned 2000 total points
ID: 22923767
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
 
LVL 2

Author Comment

by:wellso
ID: 22924171
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
 
LVL 19

Assisted Solution

by:Michael701
Michael701 earned 2000 total points
ID: 22924419
try adding an

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

in the loop, see if it's issuing the insert twice. post results here.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 2

Author Comment

by:wellso
ID: 22928159
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
 
LVL 2

Author Comment

by:wellso
ID: 22928183
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
 
LVL 2

Author Closing Comment

by:wellso
ID: 31515069
Thanks for the help, got it sorted in the end : pesky JavaScript handling in IE :)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
Following on from our article on "The Murky World of Consent and opt in", we thought we would issue some helpful guidance, not only on consent itself but knowing what information you are capturing, what you are doing with this data and how you can p…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Shows how to create a shortcut to site-search Experts Exchange using Google in the Chrome browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch the Search Engine Menu: In chrome, via you…
Suggested Courses
Course of the Month13 days, 10 hours left to enroll

750 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question