Why does this code fire again?

I've got a pop up window executing an insert statement.  I've got a code that refreshes the parent screen when the user closes the pop up window. For some reason though, another insert statement is being fired and I don't understand why.

Here's my header with the insert code and the Javascript function:

<?php
date_default_timezone_set('America/Chicago');

require_once('model_class.php');
$display=new CalendarAdmin();
$addition=$display->calendar_insert();
$display_date = date('F j, Y', strtotime($_POST['sdate']));	
?>

<!DOCTYPE html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Calendar Add Page</title>
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script type="text/javascript"> 
window.onunload = refreshParent;
function refreshParent() {
	window.opener.location.reload();
}
</script>
</head>

Open in new window


The button looks like this:

<input type="image" src="images/close_button.jpg" onclick="window.close()">

Why would my insert statement fire again after my user closes the window? What do I need to change?
brucegustPHP DeveloperAsked:
Who is Participating?
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.

Russ SuterCommented:
You have a JavaScript function that reloads a page when it unloads? I'm surprised it's not in a perpetual loop.
0
brucegustPHP DeveloperAuthor Commented:
How do I fix it?
0
Russ SuterCommented:
I'd need to see your HTML body to have any idea what you're trying to accomplish. Perhaps you can post a test page somewhere so we can see it in action?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

brucegustPHP DeveloperAuthor Commented:
Stand by...
0
brucegustPHP DeveloperAuthor Commented:
Here you go: http://brucegust.com/portfolio/calendar/

Click on a triangle and add a date. Don't do an event that spans multiple days, just go for a single date. After you do it, you'll get the next screen which invites you to close the window. At that poin, for some reason, the insert statement seems to be firing again. Only this time, it doesn't insert a real date, just part of the info.

Here's my insert page:

<?php
/date_default_timezone_set('America/Chicago');
/*session_start();
if(empty($_SESSION['email']))
{
	header("location:custom_gate.php");
	exit();
}*/

?>

<!DOCTYPE html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title><?php echo $project_name; ?>Calendar Add Page</title>
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script type="text/javascript"> 

 $(function() {
	$("#start_date").datepicker({'onSelect':function(dateText){
		  if( dateText.match(/\d\d\d\d-\d\d\-\d\d/) )
		  {
			   $(this).css({"color":"#000000"});
		   }
		  else
		  {
			   $(this).css({"color":"#CCCCCC"});
		   }
		},		
	dateFormat:"yy-mm-dd"});
});

$(function() {
	$("#end_date").datepicker({'onSelect':function(dateText){
		  if( dateText.match(/\d\d\d\d-\d\d\-\d\d/) )
		  {
			   $(this).css({"color":"#000000"});
		   }
		  else
		  {
			   $(this).css({"color":"#CCCCCC"});
		   }
		},		
	dateFormat:"yy-mm-dd"});
});

</script>
</head>

<body style="background-image:url(images/notes_background.jpg); background-repeat: no-repeat;">
	<div style="width:600px; height:560px; overflow:auto; margin-left:15px;">
	<br><br>To add an event for <b><?php echo date("F jS, Y", strtotime($_GET['the_date'])); ?></b>, fill in the fields below and click on "submit."<br><br>Thanks!<br>
	
	<br><br><table class="page_display" style="width:auto; margin:auto;"><form action="calendar_insert_execute.php" method="post">
	<tr>
		<td>
		short name
		</td>
		<td>
		<input type="text" size="65" name="short_name">
		</td>
	</tr>
	<tr>
		<td style="width:75px;;">start date</td>
		<td>
		<input type="text" size="65" name="sdate" id="start_date" style="border:1px solid #000000; color:#cccccc;" value="<?php echo date("Y-m-d", strtotime($_GET['the_date'])); ?>">
		</td>
	</tr>
	<tr>
		<td>end date</td>
		<td>
		<input type="text" size="65" name="edate" id="end_date" style="border:1px solid #000000; color:#cccccc;" value="end date">
		</td>
	</tr>
	<tr>
		<td>
		state
		</td>
		<td colspan="5">
		<select name="state">
		<option><option>
		<option>Alabama</option>
		<option>Arkansas</option>
		<option>Florida</option>
		<option>Georgia</option>
		<option>Kentucky </option>
		<option>Louisiana</option>
		<option>Mississippi</option>
		<option>North Carolina</option>
		<option>Oklahoma</option>
		<option>Region</option>
		<option>South Carolina</option>
		<option>Tennessee</option>
		<option>Texas</option>
		<option>____________________________________________________</option>
		</select>
		</td>
	</tr>
	<tr>
		<td>
		<a href="images/states.jpg" target="_blank">calendar</a>
		</td>
		<td colspan="5">
		<select name="region">
		<option><option>
		<option value="ALU">Alcatel-Lucent (ALU)</option>
		<option value="AREA">Area /National</option>
		<option value="CATN">Carolinas / Tennessee</option>
		<option value="CTX">Central Texas</option>
		<option value="DEVICE">Device</option>
		<option value="ERC">ERC</option>
		<option value="FL">Florida</option>
		<option value="GAAL">Georgia / Alabama</option>
		<option value="HGC">Houston Gulf Coast </option>
		<option value="SCTL">South Central</option>
		<option>____________________________________________________</option>
		</select>
		</td>
	</tr>
	<tr>
		<td colspan="6"><br>
		<textarea name="description" class="description">Main Body</textarea>
		</td>
	</tr>
</table>
<br><br><div style="text-align:center;"><input type="image" src="images/submit_button.png" alt="Submit" width="100"></div></form>
	</div>

</body>

</html>

Open in new window


...and here's my insert execute page:

<?php
date_default_timezone_set('America/Chicago');

require_once('model_class.php');
$display=new CalendarAdmin();
$addition=$display->calendar_insert();
$display_date = date('F j, Y', strtotime($_POST['sdate']));	
?>

<!DOCTYPE html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Calendar Add Page</title>
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script type="text/javascript"> 
window.onunload = refreshParent;
function refreshParent() {
	window.opener.location.reload();
}
</script>
</head>

<body style="background-image:url(images/notes_background.jpg); background-repeat: no-repeat;">
	<div style="width:600px; height:560px; overflow:auto; margin-left:15px;">
	<br><br>Here's the event you just inserted into the database! Click here to close this window and<br>refresh the calendar page.<br><br>
	<table class="page_display" style="width:auto; margin:auto;"><form action="calendar_insert_execute.php" method="post">
		<tr>
			<td>
			short name
			</td>
			<td>
			<input type="text" size="65" name="short_name" value=<?php echo $_POST['short_name']; ?>>
			</td>
		</tr>
		<tr>
			<td style="width:75px;;">
			start date
			</td>
			<td>
			<input type="text" size="65" name="date" value="<?php echo $display_date; ?>">
			</td>
		</tr>
		<?php
		if(isset($_POST['edate'])&& ($_POST['edate']<>"end date"))
		{
		$display_end_date = date('F j, Y', strtotime($_POST['edate']));
		?>
		<tr>
			<td>
			end date
			</td>
			<td><input type="text" size="65" name="end date" value="<?php echo $display_end_date; ?>"></td>
		</tr>
		<?php
		}
		?>
		<tr>
			<td>
			state
			</td>
			<td>
			<select name="state">
			<option selected><?php echo $_POST['state']; ?><option>
			<option>Alabama</option>
			<option>Arkansas</option>
			<option>Florida</option>
			<option>Georgia</option>
			<option>Kentucky </option>
			<option>Louisiana</option>
			<option>Mississippi</option>
			<option>North Carolina</option>
			<option>Oklahoma</option>
			<option>South Carolina</option>
			<option>Tennessee</option>
			<option>Texas</option>
			<option>____________________________________________________</option>
			</select>
			</td>
		</tr>
		<tr>
			<td><a href="images/map>region">calendar</a>
			</td>
			<td colspan="5">
			<select name="region">
			<option selected><?php echo $_POST['region']; ?><option>
			<option value="ALU">Alcatel-Lucent (ALU)</option>
			<option value="AREA">Area /National</option>
			<option value="CATN">Carolinas / Tennessee</option>
			<option value="CTX">Central Texas</option>
			<option value="Device">Device</option>
			<option value="ERC">ERC</option>
			<option value="FL">Florida</option>
			<option value="GAAL">Georgia / Alabama</option>
			<option value="HGC">Houston Gulf Coast </option>
			<option value="SCTL">South Central</option>
			<option>____________________________________________________</option>
			</select>
			</td>
		</tr>
		<tr>
			<td colspan="2"><textarea class="description"><?php echo $_POST['description']; ?></textarea></td>
			</td>
		</tr>
	</table><br>
	<div style="text-align:center;"><input type="image" src="images/close_button.jpg" onclick="window.close()"></div>
	</div>

</body>

</html>

Open in new window

0
ZvonkoSystems architectCommented:
You do submit the FORM a second time.

Change the <input type=image to <img> and you are done.
<div style="text-align:center;"><input type="image" src="images/close_button.jpg" onclick="window.close()"></div>
	
To:
<div style="text-align:center;"><img src="images/close_button.jpg" onclick="window.close()"></div>

Open in new window

0

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
brucegustPHP DeveloperAuthor Commented:
And that is why you get paid the large dollars!

Many thanks!
0
ZvonkoSystems architectCommented:
<|;-)
0
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
JavaScript

From novice to tech pro — start learning today.

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.