Solved

Form Submits Twice

Posted on 2009-05-07
9
190 Views
Last Modified: 2012-05-06
Hi there,

Having a small problem with a form, when it is submitted it inserts a duplicate record in the database, any idea what could be causing this?
<?
 
require_once('includes/session.php');
require_once('includes/oracle.php');
require_once('includes/debug.php');
 
if(isset($_GET['delete'])){
	$delete = oci_parse($connect,"DELETE FROM DOCSJOBGROUPS WHERE JOBGROUP_ID = :remove");
	@oci_bind_by_name($delete, ":remove",$_GET['delete']);
	oci_execute($delete);
}
 
if($_POST['addgroups'] == 'true'){
 
nicePrint($_POST);
	$add = oci_parse($connect,"INSERT INTO DOCSJOBGROUPS (JOBGROUP_ID, ORDER_NO_1, ORDER_NO_2) VALUES (JOBGROUP_ID_SEQ.NEXTVAL, :order_no_1, :order_no_2)");
	@oci_bind_by_name($add,":order_no_1", $_POST['order_no_1']);
	@oci_bind_by_name($add,":order_no_2", $_POST['order_no_2']);
	oci_execute($add);
	
}
 
?>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Group Orders</title>
<link href="includes/links.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="includes/js/menu.js"></script>
</head>
 
<body>
 
<? include('menu.php'); ?>
 
<p align="center" class="mainheadings">Add Grouping</p>
<form id="form1" name="form1" method="post" action="<?=$_SERVER['PHP_SELF']?>">
<p align="center">
<input type="text" name="order_no_1" id="order_no_1" /> 
<span class="mainheadings">&amp;</span> 
<input type="text" name="order_no_2" id="order_no_2" />
<input type="hidden" name="addgroups" value="true" />
</p>
<p align="center">
<input type="submit"  />
</p>
</form>
<p align="center" class="mainheadings">Current Groupings</p>
<table width="200" border="0" align="center" cellpadding="0" cellspacing="0">
<?
 
$getgroups = oci_parse($connect,"SELECT ORDER_NO_1, ORDER_NO_2, JOBGROUP_ID FROM DOCSJOBGROUPS");
oci_execute($getgroups);
 
while($row = oci_fetch_row($getgroups)){
	?>
	<tr>
	<td class="maintext"><div align="center"><?=$row[0]?></div></td>
    <td class="maintext"><div align="center"><?=$row[1]?></div></td>
    <td class="maintext"><div align="center"><a href="<?=$_SERVER['PHP_SELF']?>?delete=<?=$row[2]?>">Remove</a></div></td>
 
	</tr>
	<?
}
 
?>
</table>
</body>

Open in new window

0
Comment
Question by:wellso
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
9 Comments
 
LVL 14

Expert Comment

by:xberry
ID: 24325593
possible to post these too ?

require_once('includes/session.php');
require_once('includes/oracle.php');
require_once('includes/debug.php');
0
 
LVL 2

Author Comment

by:wellso
ID: 24325615
sure
session.php
 
<? @session_start();
if(empty($_SESSION['myusername'])){
	header("location: index.php?home=true");
}
?>
 
oracle.php
 
<? $connect = oci_pconnect('gi', 'welcom', 'xxxxx');
 
?>
 
debug.php
 
<?
function nicePrint($printme){?>
<pre><?
print_r($printme)?>
</pre>
<? } 
 
 
function jsAlert($var)
{
echo '<script type="text/javascript">
alert("'.$var.'");
</script>';
}
?>

Open in new window

0
 
LVL 14

Expert Comment

by:xberry
ID: 24326480
if there is no page reload caused by anything in your code after you submit your form - and I don't see
from your code where the page-reload could happen (your page with form is not 'home', is it?)
More likely I sense that trouble could be in your SQL-code, here:

$add = oci_parse($connect,"INSERT INTO DOCSJOBGROUPS (JOBGROUP_ID, ORDER_NO_1, ORDER_NO_2) VALUES (JOBGROUP_ID_SEQ.NEXTVAL, :order_no_1, :order_no_2)");

Not sure about the JOBGROUP_ID_SEQ.NEXTVAL syntax, but somehow my intuition says it could be
a reason (first inserting into the next available id, then again because of nextval adding an id with same
values ??)

but not sure about it, since I am not experienced with Oracle SQL and highly recommend you to post this issue
in the Oracle SQL zone, for real experts to contribute from there, too.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:bljak
ID: 24326489
What about the menu.php?
0
 
LVL 2

Author Comment

by:wellso
ID: 24326548
I have disabled all includes apart from oracle.php which has the database connect string and still no luck
0
 
LVL 2

Author Comment

by:wellso
ID: 24326566
oddly this only seems to happen in firefox and not IE
0
 
LVL 14

Accepted Solution

by:
xberry earned 500 total points
ID: 24327086
Uhhhuhh ...actually i did browse for this problem and it seems to happen with firefox,
meaning, you're not the only one:

http://forums.mozillazine.org/viewtopic.php?t=626277

some remedies given too in above url, hope it helps.

One tip from me added:

run a html validator on your site and make sure any code is absolutely neat and valid,
html, css, php, javascript ...
0
 
LVL 2

Author Closing Comment

by:wellso
ID: 31578968
not quite found the solution but on the right track, thanks for the help and sorry for slow repsonse
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ModalPopup  question 22 38
How do I add counter to html listbox using jquery 2 24
AngularJS: ng-repeat 25 20
Check input text, Number 6 28
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

740 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