This topic is locked
[SOLVED]

 Query a table for data

10/11/2010 8:00:46 PM
PHPRunner General questions
P
pcheesesteak author

I need to query a table in my database to find a record where a column matches $_Session["UserID"].
My senario: User logs in and enters a record to the 'transactions' table, but has not yet saved it. Based upon the value of $_Session["UserID"], I want to do a query to the 'employees' table and return the value of the column 'EmailAddress' into a variable, from the record where the column 'FirstName' equals $_Session["UserID"].
Table: employees:

-----------------------------

| FirstName | EmailAddress |

-----------------------------

| Roger | roger@xyz.com |

| Bob | bob@xyz.com |

| John | john@xyz.com |

-----------------------------
User 'bob' logs in, $_Session["UserID"] = 'bob'. Query is made to table 'employees' and variable $userEmailAddress = 'bob@xyz.com' is returned.
Would someone kindly give me a snippet of PHP code to do this query and return the value in a variable?
Thanks so much.
Roger.

T
tedwilder 10/12/2010



I need to query a table in my database to find a record where a column matches $_Session["UserID"].
My senario: User logs in and enters a record to the 'transactions' table, but has not yet saved it. Based upon the value of $_Session["UserID"], I want to do a query to the 'employees' table and return the value of the column 'EmailAddress' into a variable, from the record where the column 'FirstName' equals $_Session["UserID"].
Table: employees:

-----------------------------

| FirstName | EmailAddress |

-----------------------------

| Roger | roger@xyz.com |

| Bob | bob@xyz.com |

| John | john@xyz.com |

-----------------------------
User 'bob' logs in, $_Session["UserID"] = 'bob'. Query is made to table 'employees' and variable $userEmailAddress = 'bob@xyz.com' is returned.
Would someone kindly give me a snippet of PHP code to do this query and return the value in a variable?
Thanks so much.
Roger.


I would try :
$sql="select * from employees where userid=".$_Session["UserID"];

$rs=CustomQuery($sql);

$dataemployees=db_fetch_array($rs);

and mail is in $dataemployees["EmailAddress"]

so :

$userEmailAdress=$dataemployees["EmailAddress"]

if the field is UserEmailAdresse in your table employees

therfore in event before add you can fill the email field with the user mail.

P
pcheesesteak author 10/12/2010

Thank you!!!