I have a form on my site that users can enter a description into. The information is then emailed to a manager. The email includes the person's description and their username (provided by sessions when they log in)
I want the emailed info into to include the users email address which is in the database. How do I pull that information.
So far I have:
$email = "select email from users where username = '$username'";
Since the username comes from a session is this why it doesn't work?
I have a form on my site that users can enter a description into. The information is then emailed to a manager. The email includes the person's description and their username (provided by sessions when they log in)
I want the emailed info into to include the users email address which is in the database. How do I pull that information.
So far I have:
$email = "select email from users where username = '$username'";
Since the username comes from a session is this why it doesn't work?
No, a variable is a variable.
The line of code you showed does nothing more than assign a string to a variable called $email. To extract data from a database you must first connect to the database server, then select a database, then query the database (using a SQL string such as the one you showed), then extract the desired data from the result set.
Unfortunately I am still having a problem. I know this is a simple syntax problem, I just can't figure out whats going wrong. This code produces the following output:
Description: maybe
From: rjefferson
Email:Array
Its not giving me the email address from the database as I hoped.
<?php
/* Include Files *********************/
session_start();
include("login.php");
include("database.php");
/*************************************/
/* Subject and Email Variables */
$emailsubject = 'Description Form Results';
$webMaster = 'sample@sample.com';
mysql_query() doesn't return a simple string, it returns a "resource", which means it is just a pointer to what may in some cases be an array with thousands of indexes. You have to extract the individual variables (strings or numbers)from it before you can use them. Actually, I don't see how you were able to see the description and username at all. You must do something like:
Although I am trying very hard to understand this I am still having problems. My new output is:
SELECT email FROM users WHERE username = 'rjefferson'
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/content/j/a/b/jaberkjaber/html/askslicky/inner/description.php on line 24
Thank you for submitting your form
I added in the row feature to get code to produce the correct results. I never knew getting an email address from a database, based on an unique username could be so difficult. Please help.
latoyale wrote:Although I am trying very hard to understand this I am still having problems. My new output is:
SELECT email FROM users WHERE username = 'rjefferson'
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/content/j/a/b/jaberkjaber/html/askslicky/inner/description.php on line 24
Thank you for submitting your form
I added in the row feature to get code to produce the correct results. I never knew getting an email address from a database, based on an unique username could be so difficult. Please help.