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 <[email protected]>'; 'Reply-To: [email protected]' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $to1 = '[email protected]'; mail($to1, $result, $message, $headers); Thanks in Advance! Link to comment https://forums.phpfreaks.com/topic/215046-how-to-use-result-of-query-as-a-variable/ 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]')"); Link to comment https://forums.phpfreaks.com/topic/215046-how-to-use-result-of-query-as-a-variable/#findComment-1118573 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! Link to comment https://forums.phpfreaks.com/topic/215046-how-to-use-result-of-query-as-a-variable/#findComment-1118590 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 <[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. Link to comment https://forums.phpfreaks.com/topic/215046-how-to-use-result-of-query-as-a-variable/#findComment-1118597 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. Link to comment https://forums.phpfreaks.com/topic/215046-how-to-use-result-of-query-as-a-variable/#findComment-1118601 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. Link to comment https://forums.phpfreaks.com/topic/215046-how-to-use-result-of-query-as-a-variable/#findComment-1118614 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.