Jump to content


Photo

Please help. Double emails.


  • Please log in to reply
7 replies to this topic

#1 Jezreel

Jezreel
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 20 May 2006 - 08:11 PM


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:

       $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,'');

and here is my poor attempt to modify it.

       $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;


Any suggestions or help in what I did wrong please?

Thanks in advance,

Jezreel

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 20 May 2006 - 10:23 PM

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.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 Jezreel

Jezreel
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 21 May 2006 - 12:58 AM

[!--quoteo(post=375588:date=May 20 2006, 06:23 PM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ May 20 2006, 06:23 PM) View Post[/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

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 21 May 2006 - 02:00 AM

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.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#5 bobleny

bobleny
  • Members
  • PipPipPip
  • Advanced Member
  • 429 posts

Posted 22 May 2006 - 03:39 AM

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
-- www.firemelt.net --
First do me a favor and read this: JavaScript is NOT Java - Then read this: www.php.net - When your done with that, read this Topic
After that, floors open. I and anyone else will be MORE than happy to answer YOUR query! [Topic Solved]
Cheer up, the worst has yet to come...

#6 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 22 May 2006 - 06:14 AM

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.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#7 bobleny

bobleny
  • Members
  • PipPipPip
  • Advanced Member
  • 429 posts

Posted 22 May 2006 - 07:30 PM

[!--quoteo(post=375972:date=May 22 2006, 02:14 AM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ May 22 2006, 02:14 AM) View Post[/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

-- www.firemelt.net --
First do me a favor and read this: JavaScript is NOT Java - Then read this: www.php.net - When your done with that, read this Topic
After that, floors open. I and anyone else will be MORE than happy to answer YOUR query! [Topic Solved]
Cheer up, the worst has yet to come...

#8 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 22 May 2006 - 09:48 PM

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.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users