hoponhiggo Posted June 23, 2011 Share Posted June 23, 2011 Hi Guys Can anybody help me please? I am trying to set a mail $to variable with not much luck! I have some existing code which sends a 'friend request' to another user on my site if ($_GET[user]){ //gets username $username = htmlspecialchars($_GET[user]); //friend $by = $_SESSION['MM_Username']; //you $query = mysql_query("INSERT INTO `friend_requests` ( `username` , `by` ) VALUES ( '$username' , '$by' )"); //inserts the request echo ( "$username has been sent a friend request. You must now wait for it to be accepted<br> <p><a href='members.php'>Go Back</a></p>" ); //echos completion } else { echo ( "You have no more requests!" ); // or no request sent } } else { echo ( "You need to be logged in" ); //not logged in } Is there anyway i can pull out the 'friends' email address from the 'users' table and set this as a $to varaiable? Link to comment https://forums.phpfreaks.com/topic/240212-setting-the-to-varaiable/ Share on other sites More sharing options...
fugix Posted June 23, 2011 Share Posted June 23, 2011 Create a query to grab the email address where the users username equals your $_GET['user'] then use mysql_fetch_array() to grab the data and set it to $to Link to comment https://forums.phpfreaks.com/topic/240212-setting-the-to-varaiable/#findComment-1233884 Share on other sites More sharing options...
hoponhiggo Posted June 23, 2011 Author Share Posted June 23, 2011 litteraly figured it out about 2 seconds before i read this post! I used $getuser = mysql_query("SELECT * FROM `users` WHERE `username` = '$username'"); $user = mysql_fetch_array($getuser); $to = $user[email]; Thank you very much for the reply! Link to comment https://forums.phpfreaks.com/topic/240212-setting-the-to-varaiable/#findComment-1233888 Share on other sites More sharing options...
gristoi Posted June 23, 2011 Share Posted June 23, 2011 Hi, just a quick pointer, Where at all possible try to never use select *. This is purely from a performance perspective. if the email variable was the only thing you wanted returning from the db then use select email If the table you are selecting from had 20 columns ( for example ) there is no point returning the other 19 columns of data is there Link to comment https://forums.phpfreaks.com/topic/240212-setting-the-to-varaiable/#findComment-1233895 Share on other sites More sharing options...
hoponhiggo Posted June 23, 2011 Author Share Posted June 23, 2011 Ah cool. Thanks for the advice. Appreciated Link to comment https://forums.phpfreaks.com/topic/240212-setting-the-to-varaiable/#findComment-1233902 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.