spoco Posted October 1, 2009 Share Posted October 1, 2009 I have a form that is sending the data to a MySQL database. I want to send an e-mail when an ID is submitted that matches an ID already in the database. For example If I submit ID 123, Name: John, the data is written to the database If I submit ID 123, Name: John again, the data is written to the database and an e-mail is sent alerting that a duplicate ID was entered. It would be setup in an IF statement, correct? This isn't right but something like: <?php if(ID=ID)){ } $email_to = "[email protected]"; $email_subject = "Test E-Mail (This is the subject of the E-Mail)"; $email_body = "This is the body of the Email \nThis is a second line in the body!"; ?> I would appreciate any help with this. Quote Link to comment https://forums.phpfreaks.com/topic/176208-sending-an-e-mail-if-an-argument-is-made/ Share on other sites More sharing options...
The Little Guy Posted October 1, 2009 Share Posted October 1, 2009 Your if should look similar to this: if($ID==123){ Quote Link to comment https://forums.phpfreaks.com/topic/176208-sending-an-e-mail-if-an-argument-is-made/#findComment-928611 Share on other sites More sharing options...
spoco Posted October 1, 2009 Author Share Posted October 1, 2009 It has to do a lookup in the database to see if the ID exists somehow, right? Quote Link to comment https://forums.phpfreaks.com/topic/176208-sending-an-e-mail-if-an-argument-is-made/#findComment-928614 Share on other sites More sharing options...
mikesta707 Posted October 1, 2009 Share Posted October 1, 2009 yes, you can do a query like this $result = mysql_query("SELECT * WHERE field1='$variable1' AND field2='$variable2'")//variables are from your post data or wherevever //if (mysql_num_rows($result) != 0){ //send the email; } that will check for any rows matching the criteria, and if there are any, you can send an email Quote Link to comment https://forums.phpfreaks.com/topic/176208-sending-an-e-mail-if-an-argument-is-made/#findComment-928622 Share on other sites More sharing options...
spoco Posted October 1, 2009 Author Share Posted October 1, 2009 The field name that I want to check is called msis I have this code in there: $result = mysql_query("SELECT * WHERE msis='msis'") if (mysql_num_rows($result) != 0){ $email_to = "[email protected]"; $email_subject = "Test E-Mail (This is the subject of the E-Mail)"; $email_body = "This is the body of the Email \nThis is a second line in the body!"; and the page will not even load. Quote Link to comment https://forums.phpfreaks.com/topic/176208-sending-an-e-mail-if-an-argument-is-made/#findComment-928627 Share on other sites More sharing options...
mikesta707 Posted October 1, 2009 Share Posted October 1, 2009 $result = mysql_query("SELECT * WHERE msis='msis'") that will return all rows where the string string 'msis' is in the column msis. If you want to test a variable, you have to put a variable in there. And are there any errors? check the source for errors also. Quote Link to comment https://forums.phpfreaks.com/topic/176208-sending-an-e-mail-if-an-argument-is-made/#findComment-928630 Share on other sites More sharing options...
spoco Posted October 1, 2009 Author Share Posted October 1, 2009 I don't have a variable, I need it to look in the database and see if the msis number exists. Quote Link to comment https://forums.phpfreaks.com/topic/176208-sending-an-e-mail-if-an-argument-is-made/#findComment-928631 Share on other sites More sharing options...
mattal999 Posted October 1, 2009 Share Posted October 1, 2009 You need to use the FROM table in your query. "SELECT * FROM tablename WHERE msis='".$msis."'" Quote Link to comment https://forums.phpfreaks.com/topic/176208-sending-an-e-mail-if-an-argument-is-made/#findComment-928633 Share on other sites More sharing options...
mikesta707 Posted October 1, 2009 Share Posted October 1, 2009 oh yeah, sorry about that. I don't have a variable, I need it to look in the database and see if the msis number exists. what exactly is this msis number? is it constant? will it change? if it will change that you need a variable Quote Link to comment https://forums.phpfreaks.com/topic/176208-sending-an-e-mail-if-an-argument-is-made/#findComment-928637 Share on other sites More sharing options...
spoco Posted October 1, 2009 Author Share Posted October 1, 2009 I cannot get it to work. Anyone willing to take a look at the entire code? I've spent the better part of the day hung up on this. Quote Link to comment https://forums.phpfreaks.com/topic/176208-sending-an-e-mail-if-an-argument-is-made/#findComment-928639 Share on other sites More sharing options...
spoco Posted October 1, 2009 Author Share Posted October 1, 2009 The MSIS number is an ID number. It will be different for most records, basically we need an alert if a person with the same ID number is entered. Quote Link to comment https://forums.phpfreaks.com/topic/176208-sending-an-e-mail-if-an-argument-is-made/#findComment-928641 Share on other sites More sharing options...
mikesta707 Posted October 1, 2009 Share Posted October 1, 2009 post your code again. How are you supposed to tell what MSIS number to test? do you get it from a form? Quote Link to comment https://forums.phpfreaks.com/topic/176208-sending-an-e-mail-if-an-argument-is-made/#findComment-928647 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.