SokrMan Posted October 3, 2010 Share Posted October 3, 2010 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 <noreply@prahan.com>'; 'Reply-To: noreply@prahan.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $to1 = 'pratik@prahan.com'; mail($to1, $result, $message, $headers); Thanks in Advance! Quote Link to comment Share on other sites More sharing options...
Rifts Posted October 3, 2010 Share Posted October 3, 2010 $result = mysql_query("Select `email` FROM author WHERE author.id IN(SELECT authorid FROM job WHERE id = '$_POST[id]')"); Quote Link to comment Share on other sites More sharing options...
SokrMan Posted October 3, 2010 Author Share Posted October 3, 2010 Awesome! Thanks! But i'm getting a syntax error when i try to use session variables. Please help "Select `email` FROM author WHERE author.id IN(SELECT authorid FROM job WHERE id = '$_SESSION['id']')" Thanks! Quote Link to comment Share on other sites More sharing options...
SokrMan Posted October 3, 2010 Author Share Posted October 3, 2010 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 <noreply@prahan.com>'; 'Reply-To: noreply@prahan.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); $subject1 = "test"; mail($to1, $subject1, $message, $headers); Thanks in Advance. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted October 3, 2010 Share Posted October 3, 2010 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. Quote Link to comment Share on other sites More sharing options...
SokrMan Posted October 3, 2010 Author Share Posted October 3, 2010 Thanks for the response! As I mentioned before, Im a beginner in this. Would you be able to give me some sample code so i know how to do this. Thanks. Quote Link to comment 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.