homer.favenir Posted January 6, 2009 Share Posted January 6, 2009 hi, i have a form and when i submit it, it will go to another page and will get the value of the field and insert it in a table. but when i refresh the page it will again insert the stored value in the field. how can i stop the inserting of records in my table once it was refreshed? thanks in advance ??? Quote Link to comment Share on other sites More sharing options...
castis Posted January 6, 2009 Share Posted January 6, 2009 put unset($_POST) after the point you no longer need the variable. edit: unless you're manually refreshing the page, in which case... thats kinda the way it works... Quote Link to comment Share on other sites More sharing options...
homer.favenir Posted January 6, 2009 Author Share Posted January 6, 2009 if i unset the $_POST it will just empty the value of the field and will insert a null value on my table Quote Link to comment Share on other sites More sharing options...
castis Posted January 6, 2009 Share Posted January 6, 2009 if you're manually refreshing the page (via F5 and/or the refresh button) its going to keep doing that. thats how browsers work. Quote Link to comment Share on other sites More sharing options...
xtopolis Posted January 6, 2009 Share Posted January 6, 2009 After you insert the data, use a header redirect back to the same page. And or test for duplicate values before inserting (if it applies to your application). Quote Link to comment Share on other sites More sharing options...
Maq Posted January 6, 2009 Share Posted January 6, 2009 Why don't you check to see if that value is already in the table if you don't want to store it again. Or you can use sessions... Quote Link to comment Share on other sites More sharing options...
RussellReal Posted January 6, 2009 Share Posted January 6, 2009 check the http_referer? I will run a few tests.. and get back to you in a moment ok that doesn't work.. lol Quote Link to comment Share on other sites More sharing options...
prawn_86 Posted January 6, 2009 Share Posted January 6, 2009 Yeh, just use the header() function to either redirect to a new page, or back to the original page Quote Link to comment Share on other sites More sharing options...
homer.favenir Posted January 6, 2009 Author Share Posted January 6, 2009 i need to be in the page where it will insert the value in my table, i dont want to go back to the original page. how can i do that? Quote Link to comment Share on other sites More sharing options...
prawn_86 Posted January 6, 2009 Share Posted January 6, 2009 with the header() function you can choose which page you want to go to, so just redirect to that same one. i think that will work ??? Quote Link to comment Share on other sites More sharing options...
homer.favenir Posted January 6, 2009 Author Share Posted January 6, 2009 ok. ill try that, and come back here immediately afterwards Quote Link to comment Share on other sites More sharing options...
T-Bird Posted January 6, 2009 Share Posted January 6, 2009 Where there is a will there is a way. A hacked together way would be this. We're going to pretend you have a text element named 'name1'. Set a session variable called '$count'. Every time the page is visited count should be increased by one. When the php script builds the page it should change the name of the text box to fit the pattern "name".($count+1). Then whenever the page loads have it check for the $_POST["name$count"]. Every time the page reloads the script will look for a differently named POST variable. That means that only one that was just submitted will be accepted (because the name matches what PHP is looking for), any leftovers from a browser refresh will be rendered useless. edit: just occurred to me that the default name should actually be 'name1'. Quote Link to comment Share on other sites More sharing options...
RussellReal Posted January 6, 2009 Share Posted January 6, 2009 that I must say is pretty slick Where there is a will there is a way. A hacked together way would be this. We're going to pretend you have a text element named 'name0'. Set a session variable called '$count'. Every time the page is visited count should be increased by one. When the php script builds the page it should change the name of the text box to fit the pattern "name".($count+1). Then whenever the page loads have it check for the $_POST["name$count"]. Every time the page reloads the script will look for a differently named POST variable. That means that only one that was just submitted will be accepted (because the name matches what PHP is looking for), any leftovers from a browser refresh will be rendered useless. Quote Link to comment Share on other sites More sharing options...
homer.favenir Posted January 6, 2009 Author Share Posted January 6, 2009 ok. ill try that, and come back here immediately afterwards doesnt work also, its just keeps on loading my page and nothing seems to be appearing. Quote Link to comment Share on other sites More sharing options...
xtopolis Posted January 6, 2009 Share Posted January 6, 2009 This thread is not going to go anywhere without homer.favenir posting code. @the other ideas, while valid, they are complex. it's best to stick to simpler methods, in my opinion. Quote Link to comment Share on other sites More sharing options...
T-Bird Posted January 6, 2009 Share Posted January 6, 2009 After you insert the data, use a header redirect back to the same page. And or test for duplicate values before inserting (if it applies to your application). i need to be in the page where it will insert the value in my table, i dont want to go back to the original page. how can i do that? That's why you redirect to the same page. Except when it loads again, your browser will not understand it's gone back to where it started and will toss it's POST and GET data. EDIT: added xtopolis' quote to clarify where I'm coming from Quote Link to comment Share on other sites More sharing options...
homer.favenir Posted January 6, 2009 Author Share Posted January 6, 2009 ok here my code in pawnshop_tbllist, where i insert values from another page. // Page Load event function Page_Load() { $noticeflag = $_POST['x_noticeflag']; if(isset($noticeflag)) { $idnotice_tbl = $_POST['x_idnotice_tbl']; $idpawnshop_tbl = date(Y)."-".$_POST['x_idpawnshop_tbl']; $noticeDate = date(Y."-".m."-".d); $noticeLastName = $_POST['x_LastName']; $noticeFirstName = $_POST['x_FirstName']; $noticeAddress = $_POST['x_Address']; $noticePrincipal = $_POST['x_Principal']; $noticePrincipal = str_replace(',', '', $noticePrincipal); $noticePrincipal = explode('.', $noticePrincipal); $noticePrincipal = $noticePrincipal[0]; $noticeAmountWords = $_POST['x_AmountWords']; $noticeItemType = $_POST['x_ItemType']; $noticeNetProceeds = $noticePrincipal; $noticeInterest =$_POST['x_Interest']; //$myInterest = (int)$myInterest/100; $noticeServiceCharge = $_POST['x_ServiceCharge']; $noticeDST = $_POST['x_DST']; $noticeDescription = $_POST['x_Description']; $noticeNote = $_POST['x_Note']; $noticeAuthoRep = CurrentUserName(); $noticeMaturityDate = date("Y-m-d", mktime(0,0,0,date("m"),date("d")+30,date("Y"))); $noticeExpiryDate = date("Y-m-d", mktime(0,0,0,date("m"),date("d")+120,date("Y"))); $noticeServiceType = $_POST['x_ServiceType']; $noticeBranch = ew_CurrentUserIP(); $noticeGrams = $_POST['x_Grams']; $noticeKarats = $_POST['x_Karats']; $noticeQuantity = $_POST['x_Quantity']; $sInsertSql = "insert into pawnshop_tbl (PawnTicketNo, DateLoan, LastName, FirstName, Address, Principal, AmountWords, ItemType, NetProceeds, Interest, ServiceCharge, DST, Description, Note, AuthoRep, MaturityDate, ExpiryDate, ServiceType, Branch, Grams, Karats, Quantity) values ('$idpawnshop_tbl', '$noticeDate', '$noticeLastName', '$noticeFirstName', '$noticeAddress', '$noticePrincipal', '$noticeAmountWords', '$noticeItemType', '$noticeNetProceeds', '$noticeInterest', '$noticeServiceCharge', '$noticeDST', '$noticeDescription', '$noticeNote', '$noticeAuthoRep', '$noticeMaturityDate', '$noticeExpiryDate', '$noticeServiceType', '$noticeBranch', '$noticeGrams', '$noticeKarats', '$noticeQuantity')"; $sDelSql = "delete from notice_tbl where idnotice_tbl = " . $idnotice_tbl; $GLOBALS["conn"]->Execute($sInsertSql); $GLOBALS["conn"]->Execute($sDelSql); }else{ //echo 'No'; } //echo "Page Load"; } "if(isset($noticeflag))" should stop the $_POST, but it doesnt work Quote Link to comment Share on other sites More sharing options...
T-Bird Posted January 6, 2009 Share Posted January 6, 2009 Sorry, but that code doesn't seem to be useful to answering your question. You've been given at least two methods for solving the problem. Try to implement one of them, then using the post-implementation code let us help you debug that to get to a finished working product. xtopolis' method is quite simple. I'd start there. Quote Link to comment Share on other sites More sharing options...
homer.favenir Posted January 6, 2009 Author Share Posted January 6, 2009 ok, im successfully did it! here what i did. in my notice_tbllist.php form (where all the values is entered) i place: $_SESSION['reload_page'] = TRUE; before the submit button in my pawnshop_tbllist (where the $_POST is waiting) i insert if($_SESSION['reload_page'] == TRUE) { $_SESSION['reload_page'] = FALSE; // and the rest of the code }else{ //do nothing } the session will become false and will stop inserting. i finally got it! im succesfull! thanks for the help guys..... Quote Link to comment Share on other sites More sharing options...
DarkSuperHero Posted January 6, 2009 Share Posted January 6, 2009 nice solution...its nice and simple also...props! Quote Link to comment Share on other sites More sharing options...
homer.favenir Posted January 6, 2009 Author Share Posted January 6, 2009 the purpose of my script is it will insert record to pawnshop_tbl, and will delete record from notice_tbl. inserting the record to pawnshop_tbl from notice_tbl is fine, but when i refresh the page it will insert again the same values in pawnshop_tbl, resulting to multiple same record. Quote Link to comment 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.