Jump to content

How to use result of query as a variable?


SokrMan

Recommended Posts

Hello,

So I have a content management site set up, but I'm stuck on one part. I have a query.

Select `email` FROM author WHERE author.id IN(SELECT authorid FROM job WHERE id = '$_POST[id]')

 

I'm a beginner in PHP and SQL. Basically I need the query to run, it will come out with one result and I need that to be where the email is sent to.

 

This is the existing code I have for sending out the email

$subject = " Job Application Confirmation";

$message = "Hello $_POST[name] , \r\rYou, or someone using your email address, has applied for the job: $text Using the Resource Locator at Prahan.com. Keep this as future reference. \r\r Full Name: $_POST[name] \r Location: $_POST[location] \r Email: $_POST[email] \r Additional Information: $_POST[info] \r Job ID: $id  \r Job Name: $text  \r \r Expect a response shortly. \r\r Regards, Prahan.com Team";

$headers = 'From: Prahan.com Team <[email protected]>';

    'Reply-To: [email protected]' . "\r\n" .

    'X-Mailer: PHP/' . phpversion();

$to1      = '[email protected]';

mail($to1, $result, $message, $headers);

 

Thanks in Advance!

For some reason, this code

$result = mysql_query("Select `email` FROM author WHERE author.id IN(SELECT authorid FROM job WHERE id = $id)"); $to1 = PRINT $result;

echo "An email has been sent to the Job Poster with your contact information. You will recieve a confirmation email at $to1 . Remeber to check your junk mail as well.";

isn't working.

 

The email of the author should = $to1. Here is the whole page's code

 

if ($_POST['form_submitted'] == '1') {
##User is registering, insert data until we can activate it
session_start();
$id = $_SESSION['id'];
$text = $_SESSION['text'];
$authorid = $_SESSION['authorid'];
$name = ($_POST[username]);
$info = ($_POST[info]);
$location = ($_POST[location]); 
$email = ($_POST[email]);

$db_host = 'localhost';
$db_user = '************';
$db_pwd = '*****';

$database = '*****';
$table = 'job';

if (!mysql_connect($db_host, $db_user, $db_pwd))
    die("Can't connect to database");

if (!mysql_select_db($database))
    die("Can't select database");


$result = mysql_query("Select `email` FROM author WHERE author.id IN(SELECT authorid FROM job WHERE id = $id)"); $to1 = PRINT $result;

echo "An email has been sent to the Job Poster with your contact information. You will recieve a confirmation email at $to1 . Remeber to check your junk mail as well.";

##Send activation Email

$to      = $_POST[email];

$subject = " Job Application Confirmation";

$message = "Hello $_POST[name] , \r\rYou, or someone using your email address, has applied for the job: $text Using the Resource Locator at Prahan.com. Keep this as future reference. \r\r Full Name: $_POST[name] \r Location: $_POST[location] \r Email: $_POST[email] \r Additional Information: $_POST[info] \r Job ID: $id  \r Job Name: $text \r Author's Email: $to1  \r \r Expect a response shortly. \r\r Regards, Prahan.com Team";

$headers = 'From: Prahan.com Team <[email protected]>';

    'Reply-To: [email protected]' . "\r\n" .

    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);

$subject1 = "test";

mail($to1, $subject1, $message, $headers);

 

Thanks in Advance.

The syntax is wrong. It has been written so that you're trying to use a result resource as a value.  You need to take the value out of $result with mysql_fetch_assoc(), mysql_result(), etc for it to be usable.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.