Jump to content

Archived

This topic is now archived and is closed to further replies.

Jezreel

Please help. Double emails.

Recommended Posts


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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[!--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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.php
Just, if you could, try not to send me to many emails lol

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[!--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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

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.