Forums
This topic is locked
Email alert for database
Posted 17 years ago
1
has voted
17 years ago Steve Lawrie posted:
Hello,I am trying to have a form alert with an email for every time an entry goes into a database. But I get several emails and no entries into the database and I assume that the page is sending an email everytime the page is accessed, rather than having an entry.
<b><?php mail($to=' steve@sculpturedlight.com ', $subject='Entry in Sculptured Light Database', $body='There is an entry in the Query section of the databse.');?></b>
I am not sure if I am going about this the right way.
Thanks
Replies
Replied 17 years ago
17 years ago Alan C replied:
we could do with seeing a little more of the surrounding code, to make sure that the email only gets sent after the insert has been successful
Replied 17 years ago
17 years ago Steve Lawrie replied:
Hello,
I eventually worked out a way of fixing it. It seems that everytime someone viewed the page an email was sent to whatever the address is. I noticed that there is a variable in the insert "$Result1" that Dreamweaver uses to parse the information. So therefore if something was indeed sent to the database there would have to be a value. So if you used a conditional to say "if" $Result1 had anything, do something. I'm not very advanced in this so it took a while.
<b>if ($Result1 >1){
mail($to=' name@emailaddress.com ', $subject='Entry in Someones Database', $body='There is an entry in the Query section of the databse.');
}</b>
Not rocket science but when you haven't seen it done before : ) I wish there was a course that did only PHP/MySQL
I eventually worked out a way of fixing it. It seems that everytime someone viewed the page an email was sent to whatever the address is. I noticed that there is a variable in the insert "$Result1" that Dreamweaver uses to parse the information. So therefore if something was indeed sent to the database there would have to be a value. So if you used a conditional to say "if" $Result1 had anything, do something. I'm not very advanced in this so it took a while.
<b>if ($Result1 >1){
mail($to=' name@emailaddress.com ', $subject='Entry in Someones Database', $body='There is an entry in the Query section of the databse.');
}</b>
Not rocket science but when you haven't seen it done before : ) I wish there was a course that did only PHP/MySQL
Replied 17 years ago
17 years ago Steve Lawrie replied:
Woops correction $Result >0
Replied 17 years ago
17 years ago Alan C replied:
great - I think you're right about the course, I spent and still do spend ages reading and trying things out, I know it takes me longer to do things than it ought to but that's one of the consequences of working on your own, you don't get that support that a group gives - I used to work in an office with several of us on a project so you could always shout and get quick support