Jump to content

Sending an e-mail if an argument is made


spoco

Recommended Posts

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 = "somebody@email.com";
$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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 = "someone@company.com";

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.