paradoxic Posted September 15, 2007 Share Posted September 15, 2007 <?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. Quote Link to comment https://forums.phpfreaks.com/topic/69503-script-running-3-times/ Share on other sites More sharing options...
jscix Posted September 15, 2007 Share Posted September 15, 2007 <?php if($page == "" || $page=="Home") { include("includes/Home.php"); } elseif (file_exists("includes/$page.php")) { include("includes/$page.php"); } else { include("includes/404.php"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/69503-script-running-3-times/#findComment-349236 Share on other sites More sharing options...
rarebit Posted September 15, 2007 Share Posted September 15, 2007 Do you want to post the code that it includes? Quote Link to comment https://forums.phpfreaks.com/topic/69503-script-running-3-times/#findComment-349238 Share on other sites More sharing options...
paradoxic Posted September 15, 2007 Author Share Posted September 15, 2007 $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. Quote Link to comment https://forums.phpfreaks.com/topic/69503-script-running-3-times/#findComment-349244 Share on other sites More sharing options...
jscix Posted September 15, 2007 Share Posted September 15, 2007 Are you passing the value to your index.php, which then includes the script, which handles the database query? Why not link the form directly to a script that handles the query? Quote Link to comment https://forums.phpfreaks.com/topic/69503-script-running-3-times/#findComment-349247 Share on other sites More sharing options...
rarebit Posted September 15, 2007 Share Posted September 15, 2007 I'm at a loss, but you could try 'include_once()'... http://uk3.php.net/manual/en/function.include-once.php Similar to '#ifdef' in c. Quote Link to comment https://forums.phpfreaks.com/topic/69503-script-running-3-times/#findComment-349248 Share on other sites More sharing options...
Crew-Portal Posted September 16, 2007 Share Posted September 16, 2007 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'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/69503-script-running-3-times/#findComment-349377 Share on other sites More sharing options...
paradoxic Posted September 18, 2007 Author Share Posted September 18, 2007 Essentially all those suggestions work the same. I think the root of the problem lies elsewhere. Can anyone else offer suggestions or help? Quote Link to comment https://forums.phpfreaks.com/topic/69503-script-running-3-times/#findComment-350240 Share on other sites More sharing options...
markjoe Posted September 18, 2007 Share Posted September 18, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/69503-script-running-3-times/#findComment-350267 Share on other sites More sharing options...
paradoxic Posted September 18, 2007 Author Share Posted September 18, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/69503-script-running-3-times/#findComment-350307 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.