Jezreel Posted May 20, 2006 Share Posted May 20, 2006 Basically, I have a message system on my site and sometimes when a user refreshes their screen or "back buttons" to the page and resends the message the receipent obviously gets the message twice or even three times.So, I want to check the database prior to a message being sent to see if a message has been sent from the same user to the same user within 200 seconds and if it has, to not send it agan.I apologize for being a beginner programmer/coder but we all have to start somewhere. Here is the code prior to my poor attempt to modify it:[code] $sql_query="insert into network (mem_id,frd_id) values ($m_id,$frm->frm_id),($frm->frm_id,$m_id)"; sql_execute($sql_query,''); $sql_query="delete from messages_system where mes_id='$inv_id'"; sql_execute($sql_query,''); $sql_query="insert into messages_system (mem_id,frm_id,subject,body,type,new,folder,date) values ('$frm->frm_id','$m_id','$subject','$answer','message','new','inbox','$now')"; sql_execute($sql_query,'');[/code]and here is my poor attempt to modify it.[code] $sql_query="insert into network (mem_id,frd_id) values ($m_id,$frm->frm_id),($frm->frm_id,$m_id)"; sql_execute($sql_query,''); $sql_query="delete from messages_system where mes_id='$inv_id'"; sql_execute($sql_query,''); $now=time(); $hic=$now + 200; $sql_query="select * from messages_system where mes_id='$inv_id' order by date limit 0,1"; $hiccup=sql_execute($sql_query,'get'); //250 if ($hiccup <= $hic) exit;[/code]Any suggestions or help in what I did wrong please?Thanks in advance,Jezreel Quote Link to comment Share on other sites More sharing options...
fenway Posted May 20, 2006 Share Posted May 20, 2006 While you could handle this in the DB, the "correct" way is simply to redirect to a new page _after_ sending the e-mail, such that there are no refresh issues. Quote Link to comment Share on other sites More sharing options...
Jezreel Posted May 21, 2006 Author Share Posted May 21, 2006 [!--quoteo(post=375588:date=May 20 2006, 06:23 PM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ May 20 2006, 06:23 PM) [snapback]375588[/snapback][/div][div class=\'quotemain\'][!--quotec--]While you could handle this in the DB, the "correct" way is simply to redirect to a new page _after_ sending the e-mail, such that there are no refresh issues.[/quote]I understand that.. but sometimes they refresh the page for whatever reason before sending the initial one which causes problems with the database and your solution still doesn't solve the "Back" issue.Thanks for responding,Jezreel Quote Link to comment Share on other sites More sharing options...
fenway Posted May 21, 2006 Share Posted May 21, 2006 I'm not sure I understand... if they refresh the page before sending the initial one, how can anything happen?It sounded like you doing the DB stuff on submit of the page. Second, it does solve the "back" problem, since they'd have to submit yet again to trigger a new email, which may even be desired. Quote Link to comment Share on other sites More sharing options...
bobleny Posted May 22, 2006 Share Posted May 22, 2006 I also have an email system using a database. I guess its not really an email system as it doesn’t email anything. Anyways, this system is composed of 4 files. The one is a simple delete feature and is ill relevant to your situation.For the other 3 pages though, the first page is a form. They fill out the form and click submit. When this happens it takes the 2 a second page which only inputs the data into the database. This is an extremely small page and is never actually seen!echo "<META HTTP-EQUIV='Refresh' delay=.5 CONTENT= '.5;URL=index.php'>";That code means the user is only there for .5 seconds and is not even noticed by the browser. So when the click the back button it actually goes back to the form and not the page that inserts the data. There by eliminating the possibility of accidentally reentries.If you’d like to see the example, www.firemelt.net/mail.phpJust, if you could, try not to send me to many emails lol Quote Link to comment Share on other sites More sharing options...
fenway Posted May 22, 2006 Share Posted May 22, 2006 Yeah, that could work too -- but there's no need to go via an intermediate page when printing out a proper location header will suffice. Quote Link to comment Share on other sites More sharing options...
bobleny Posted May 22, 2006 Share Posted May 22, 2006 [!--quoteo(post=375972:date=May 22 2006, 02:14 AM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ May 22 2006, 02:14 AM) [snapback]375972[/snapback][/div][div class=\'quotemain\'][!--quotec--]Yeah, that could work too -- but there's no need to go via an intermediate page when printing out a proper location header will suffice.[/quote]Could you please elaborate? Maybe explain how and what you mean because I’m new to the mysql and php stuff and if you can do it with out an intermediate page I’d like to try it!Thanks Quote Link to comment Share on other sites More sharing options...
fenway Posted May 22, 2006 Share Posted May 22, 2006 I don't know how to do this in PHP specifically, since I do everything in Perl. However, the basic idea is that you process all of the posted information, redirect to a new page (without re-posting info), then generate your e-mail in the background. I'm sure there are others around here who know exactly how PHP handles Location headers; if not, I'm sure there are tutorials aplenty. 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.