Get ready for BLACK FRIDAY shopping starting in

Forums

PHP

This topic is locked

Email alert for database

Posted 08 Oct 2007 23:56:12
1
has voted
08 Oct 2007 23:56:12 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>&lt;?php mail($to=' ', $subject='Entry in Sculptured Light Database', $body='There is an entry in the Query section of the databse.');?&gt;</b>

I am not sure if I am going about this the right way.

Thanks

Replies

Replied 10 Oct 2007 11:37:34
10 Oct 2007 11:37:34 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 11 Oct 2007 01:21:22
11 Oct 2007 01:21:22 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 &gt;1){
mail($to=' ', $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 11 Oct 2007 01:23:05
11 Oct 2007 01:23:05 Steve Lawrie replied:
Woops correction $Result &gt;0
Replied 15 Oct 2007 13:11:50
15 Oct 2007 13:11:50 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

Reply to this topic