bobkoure Posted May 9, 2009 Share Posted May 9, 2009 Hi, I've got a PHP app that writes some information to a MySQL database. To keep the data from being entered twice, I've got a separate "update database" PHP file that should not go to the browser at all (no HTML other than header('location:...'). The puzzle is that the data still gets entered in duplicate. I've written a bit of code to detect this double load by using the database (IP of requesting workstation, time of last request from that IP). This catches the double load and keeps it from being a double write - but I still have a case of the WTFs. The calling page is calling through a simple page action <form class="page" id="form1" name="form1" method="get" action="updateDB.php" onsubmit="return checkinput();"> The called file (hard to call it a "page"), gets all options passed to it via Get, detects a second call from the same IP within 3 seconds, and does not write to the db if it detects this second call. After all this, I have $options = buildOptions($startSN); // builds all the options in the "?x=1&y=2" format $location = sprintf('location:%s%s','askdone.php',$options); header($location); So... is it just normal for PHP to load a file twice? I know this mostly doesn't matter, but I'd love to know if I'm approaching this problem the right way (or wrong, of course). Thanks! ...and please ask for more details if that might help. I'm a newbie here and not sure how much "stuff" to put into a question. Which forwards fine - but I get that second load Link to comment https://forums.phpfreaks.com/topic/157438-php-loading-files-twice-normal/ Share on other sites More sharing options...
trq Posted May 9, 2009 Share Posted May 9, 2009 The script wouldn't be getting called twice, there must be something in your code. Can we see all of updateDB.php ? Link to comment https://forums.phpfreaks.com/topic/157438-php-loading-files-twice-normal/#findComment-829969 Share on other sites More sharing options...
bobkoure Posted May 9, 2009 Author Share Posted May 9, 2009 Absolutely <?php require_once("include/common.php"); require_once("./include/open_db.php"); // this sits between howmany.php and askdone.php // it updates the "counter" and writes all db records as though the labels were already printed // (this is a request from Eric C. - floor folks were *not* pressing the "Yes" key in askdone, so records were being lost) // All URL vars are passed forward by building the URL "by hand" - no browser involved // this PHP file hould never be visible to the user - it jumps via "header(location) function buildOptions($StartSN) { $options = '?'.'StartSN='.(string)$StartSN; $get = $GLOBALS['_GET']; foreach($get as $key => $val) { $options=$options.sprintf('&%s=%s',$key,$val); } return $options; } if((isset($_GET['Series']))&&(isset($_GET['Qty']))) { $qty = $_GET['Qty']; $series = $_GET['Series']; $series_base = $series_list[$series]; if($qty > 0) { /* $startSN = ReserveSnBlock($qty); // we've now "reserved" $startSN to $startsn + $qty WriteRecordToDb($series_base,$startSN+$i); // write to the DB, using $series_base[dbItems] */ $refresh = IsRefresh($qty); if($refresh == 0) { $startSN = ReserveSnBlock($qty); // we've now "reserved" $startSN to $startsn + $qty // printf('startsn %s qty %s<br>',$startSN,$qty); for ($i=0; $i<$qty; $i++) { WriteRecordToDb($series_base,$startSN+$i); // write to the DB, using $series_base[dbItems] } } else { // this is a refresh - don't write to the DB, don't update counters, just set old startSN $startSN = $refresh; } $options = buildOptions($startSN); $location = sprintf('location:%s%s','askdone.php',$options); header($location); } } ?> Qty is passed along the URL common.php, along with $series are use to get a list of what fields to write to the db. Thanks! Link to comment https://forums.phpfreaks.com/topic/157438-php-loading-files-twice-normal/#findComment-829987 Share on other sites More sharing options...
bobkoure Posted May 11, 2009 Author Share Posted May 11, 2009 I've tried several "bare bones" sets of PHP files and can't create this, so I have to conclude that it's somewhere in the navigation system that I have inherited. Sigh... So... do I mark this as "solved", "bad question" or what? Link to comment https://forums.phpfreaks.com/topic/157438-php-loading-files-twice-normal/#findComment-831484 Share on other sites More sharing options...
PFMaBiSmAd Posted May 11, 2009 Share Posted May 11, 2009 Your browser is probably requesting the page twice. What is the javascript for the checkinput() function? Also, what browser are you testing with and have you tried with a different one? Link to comment https://forums.phpfreaks.com/topic/157438-php-loading-files-twice-normal/#findComment-831513 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.