Forum Moderators: coopster

Message Too Old, No Replies

automatic emails

based on selection from dynamic dropdow menu

         

brancook

3:20 pm on Oct 29, 2007 (gmt 0)

10+ Year Member



I want to send automatic emails based on a selection from a dynamic dropdox menu once it is selected and submitted. The dropdown menu references an id from a table. What would my if statement look like? So if an id is selected a user is notified via email.

jatar_k

4:13 pm on Oct 31, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you could just select it from the db using the id that the user selected

brancook

6:03 pm on Oct 31, 2007 (gmt 0)

10+ Year Member



I'm having some trouble figuring out what $message would look like. Do I need to make another sql statement?

jatar_k

6:12 pm on Oct 31, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



for the status?

brancook

6:22 pm on Oct 31, 2007 (gmt 0)

10+ Year Member



Yes, for the status to insert the status name from the option value instead of the id. So I'd want the status to read Status = "Estimate" in the email instead of Status = "2".

jatar_k

7:11 pm on Oct 31, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



just add a

$q = "select status_name FROM status where id=" . $id;

and put the value in the message

brancook

7:21 pm on Oct 31, 2007 (gmt 0)

10+ Year Member



I'm still just getting the id displayed...

jatar_k

7:24 pm on Oct 31, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



did you execute the query and then get the value back from mysql?

if so you should have the status_name in some variable you named and then you can put that into the message.

if you did that and it isn't working then show me the code

brancook

8:53 pm on Oct 31, 2007 (gmt 0)

10+ Year Member



This is my latest try:

$id = $_POST['status'];
$ok = @mysql_query($sql);
if (!$ok) {
exit('Database error storing file: ' . mysql_error());
} elseif ($ok) {
$to = '';
if ($id == 2 ¦¦ $id == 10) $to = 'example@gmail.com';
else $to = 'me@example.com';
$q = "select status.status_name FROM status where status.status_name=" . $id;
if ($q) $message = 'status_name';
$subject = "current email test";
mail($to, $subject, $message);
echo('File uploaded successfully!<br />example has been notified of your upload and you will recieve an estimate soon<br /><a href="http://www.example.com/sta_fileshare/sta_rma_upload.php">Back to STA File Uploader</a>');
}
}

I guess I really just don't see where to pull the name and how to relate it to it's id. It seems like it should be simple but I just don't see it.

[edited by: jatar_k at 9:33 pm (utc) on Oct. 31, 2007]
[edit reason] examplified [/edit]

jatar_k

9:33 pm on Oct 31, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you'll need to send the query to the db

$id = $_POST['status'];
$ok = @mysql_query($sql);
if (!$ok) {
exit('Database error storing file: ' . mysql_error());
} elseif ($ok) {
$to = '';
$message = '';
if ($id == 2 ¦¦ $id == 10) $to = 'example@gmail.com';
else $to = 'me@example.com';
$q = "select status_name FROM status where status_name=" . $id;
$query = mysql_query($q);
if ($row = mysql_fetch_array($query)) {
$message .= $row['status_name'];
}
$subject = "current email test";
mail($to, $subject, $message);
echo('File uploaded successfully!<br />example has been notified of your upload and you will recieve an estimate soon<br /><a href="http://www.example.com/sta_fileshare/sta_rma_upload.php">Back to STA File Uploader</a>');
}
}

that should work, you can then append anything to message by using

$message .= 'next value here';

brancook

1:11 am on Nov 1, 2007 (gmt 0)

10+ Year Member



Thanks, I'll give that a try...

brancook

2:12 am on Nov 1, 2007 (gmt 0)

10+ Year Member



Hey looks like this works, I did have to tweak the $q statement to look like this:

$q = "select status.status_name, status.id FROM status where id=" .$id;

Thanks for all your help!

This 41 message thread spans 2 pages: 41