Current location: Hot Scripts Forums » Programming Languages » PHP » Emailing from query results


Emailing from query results

Reply
  #1 (permalink)  
Old 11-08-03, 01:10 PM
Aaronn's Avatar
Aaronn Aaronn is offline
Newbie Coder
 
Join Date: Nov 2003
Location: Spokane Washington
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Question Emailing from query results

I'm trying to create a script that when a "new user" submits a form and there info is added to the database it emails the "agent" that is associated with the "access code" the new user submitted. right now I have it automatically send an email to the user but I dont know how to make it send to the associated agent. The agents and the users are on different tables. So far my code looks like this:

<?

$DBhost = "localhost";
$DBuser = "username";
$DBpass = "password";

$db_name = "database_name";
$login_table = "user";

$connection = @mysql_connect($DBhost,$DBuser,$DBpass) or die("Couldn't Connect.");
$db = @mysql_select_db($db_name, $connection) or die("Sorry, I could not select the requested Database ");


if ( isset( $first_name ) && isset( $last_name ) && isset( $phone ) && isset( $product )&& isset( $email )&& isset( $access_code) ) {
$dberror = "You have not submitted all the needed data";
$ret = add_to_database( $first_name, $last_name, $phone, $product, $email, $access_code, $dberror );
if ( ! $ret )
print "ERROR: $dberror<br>";
else
$reply= "thank you for your patience";
$response_mail = "Hello $first_name $last_name\n I wanted to personally thank you for viewing our presentation. An agent in your area will be contacting you soon to discuss a $product that is right for you. Again thank you for taking the time to check us out.";
$header = "From: email_address";
$subject = "Thank You for Viewing Our Presentation";
mail("$email","$subject","$response_mail","$header ");
} else {
write_form();
}

function add_to_database( $first_name, $last_name, $phone, $product, $email, $access_code ) {
$link = mysql_pconnect( "localhost","$DBuser","$DBpass" );
if ( ! $link ) {
$dberror = "Couldn't connect to Database";
return false;
}
if ( ! mysql_select_db( $db, $link )){
$dberror = mysql_error();
return false;
}
$query= "INSERT INTO user ( first_name, last_name, phone, product, email, access_code )
values( '$first_name', '$last_name', '$phone', '$product', '$email', '$access_code' )";
if ( ! mysql_query( $query, $link ) ) {
$dberror + mysql_error();
return false;
}
return true;
}

?>

I'm not exactly sure as to where to start, any help would be greatly appreciated. except I know I'd have to run a query like:
"SELECT email FROM $login_table WHERE access_code = \"$access_code\"";
but from there I get confused about how it should be written.
-AaronN
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 11-09-03, 12:45 AM
Aaronn's Avatar
Aaronn Aaronn is offline
Newbie Coder
 
Join Date: Nov 2003
Location: Spokane Washington
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Smile

Nevermind, I was able to figure it out. I wrote this code to make it happen:

$sql = "SELECT email FROM agent WHERE access_code = $access_code";
$result = @mysql_query($sql, $connection) or die("Couldn't execute query.");
$row = mysql_result($result, $m, 'email');
$agent_mail = "$first_name $last_name has just viewed your presentation, they can be reached at $phone or you can email them at $email, they want info on $product";
$header = "From: email@email.com";
$subject = "Someone Viewed your presentation";
mail("$row","$subject","$agent_mail","$header");

probably not the prettiest code but it works, and I'm still learning.

-AaronN
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
MOHAA Server Query - ASP Stealth Website Reviews 1 11-27-04 11:38 AM
Make a query that makes a field a link to the entire row mdhall PHP 8 10-09-03 07:18 PM
query results in multiple columns SnowCrash PHP 2 10-09-03 04:08 AM
Which way to display results from mysql Peter_web PHP 2 09-13-03 06:39 PM
Using CDONTS to email Checkbox results AkaMadDiSk ASP 1 07-23-03 06:32 PM


All times are GMT -5. The time now is 12:23 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.