Jump to content

Recommended Posts

<?php
if($page=="" || $page=="Home") {
include("includes/Home.php");
} else {
if(file_exists("includes/$page.php"))
{ 
include("includes/$page.php"); 
} else {
include("includes/404.php"); 
}
}
?>

I use this code for including the main pages of my site while keeping the banner and such constant.

 

For some reason when I send out emails or add a row to a (MySQL) database, it sends 3 of the same emails or adds 3 of the same database rows. I can't seem to figure out why it would do this, but I'm almost positive it has to do with the include script because I have other single page scripts (that dont use the include script above) on my site that dont do it. One other note, it only seems to happen only upon a form submission (both post and get) because I have a script that adds a bookmark when a certain GET variable is set and that will always only add one row.

 

I've been struggling with this problem for a while so I appreciate any help.

Link to comment
https://forums.phpfreaks.com/topic/69503-script-running-3-times/
Share on other sites

$action = make_safe($_GET['action']); 
$first_name = $_GET['first_name'];
...for all fields

if($action == 'upload') { 
$query = "INSERT INTO orders 
                                    SET item='".$item."',
				  first_name='".$first_name."',
				  last_name='".$last_name."',
				  email='".$email."',
				  address='".$address."',
				  city='".$city."',
				  state='".$state."',
				  zip='".$zip."',
				  phone='".$phone."',
				  payment_method='".$payment_method."',
				  date='".$date."',
				  heat_pack='".$heat_pack."',
				  grow_guide='".$grow_guide."'";
$result = mysql_query($query) or die("Query failed : " . mysql_error());

} else {

<form action="index.php" method="get" enctype="application/x-www-form-urlencoded" name="orderform">
<input name="first_name" type="text" id="first_name" size="25">
...more fields
<input type="hidden" name="page" value="Order" />
<input type="hidden" name="action" value="upload" />
</form>

}

 

Thats basically the code I have.

 

I tried switching my include code to your suggestion jscix, and now it seems to be adding 2 rows/emails instead of three.

This is pretty much the same type of script I deleveloped a while back starting PHP, Try this:

 

        <?php 
if (isset($error)){
echo '<p>';
echo $error;
echo '<p>';
}
echo '<p>';
	if ($page == NULL){
		include ('pages/home.php');
	}
		elseif (file_exists('pages/' . $page . '.php')){
			include ('pages/' . $page . '.php');
		}
			else include ('pages/error404.php');
?>

There appears to be 2 seperate problems, the first solved by the first reply (jscix).

The second...

How is the form submitted?

What else happens (code wise) after the submissionis handled?

If you are redirecting back to the page to display after inserting data, double check the value of $_GET['action'].

 

I think we'll need some actual code to figure anything out.

Ok I just did some trials and found out if I remove the google ad from my page there is no longer a problem (its on the index page with the include script). So now I'm kinda at a stand still. Does anyone have any suggestions as to what to do at this point?

 

Here is the google ad code (its straight off their web site):

<script type="text/javascript"><!--
google_ad_client = "pub-5413435956001764";
google_alternate_ad_url = "http://salviasource.org/includes/wiseadvancebanner.htm";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text_image";
google_ad_channel ="";
google_color_border = "009900";
google_color_bg = "7C7C7C";
google_color_link = "F2F2F2";
google_color_url = "333333";
google_color_text = "000000";
//--></script>

<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.