ricerocket Posted March 14, 2008 Share Posted March 14, 2008 Hi, if I wanted to get a username out of a database but I only have the email how would I create a query that gets the username using the email? And then how do I turn that into a variable with I can use to display the email wherever I print the variable...? Quote Link to comment Share on other sites More sharing options...
Guest Posted March 14, 2008 Share Posted March 14, 2008 Assuming the database has fields called "username" and "emailaddress": SELECT username FROM UsersTable WHERE emailaddress='test@test.com' Quote Link to comment Share on other sites More sharing options...
ricerocket Posted March 14, 2008 Author Share Posted March 14, 2008 thanks, right now I have this: $username=$_SESSION['pwngame']; $getuser="SELECT * from eatyou_login where eatname='$username'"; $getuser2=mysql_query($getuser) or die("Could not get user"); $getuser3=mysql_fetch_array($getuser2); but how would I turn that into a variable Quote Link to comment Share on other sites More sharing options...
Guest Posted March 14, 2008 Share Posted March 14, 2008 Now, here's the thing, from your last post, I have a slight suspicion that you didn't write that script yourself, nor do you really understand what it does fully (sorry I don't mean to be offensive, if I come off that way). If that's the case, the advice I'm about to give you might not make much sense, and explaining it bit by bit would be impossible; you'd have to take the time to learn the basics of PHP. If I'm completely wrong, sorry about that. And here goes: // Assuming you'll get the email address from a form $email= $_POST['email']; // Assuming there's a field in eatyou_login called "eatemail" $getuser="SELECT * from eatyou_login where eatemail='$email'"; $getuser2=mysql_query($getuser) or die("Could not get user"); $getuser3=mysql_fetch_array($getuser2); // $getuser3['username'] contains the username with the email address inside $email, // if one was found. Quote Link to comment Share on other sites More sharing options...
ricerocket Posted March 14, 2008 Author Share Posted March 14, 2008 Yea your right, I got that little snippet off of a previous script I had someone do for me. Your code works and I understand it, but I need to get the email from the database using the username. The username is stored in the session/cookie which I've turned into the variable $username. with the username I need to be able to select the email address from the user table in the database. How would I do that? Quote Link to comment Share on other sites More sharing options...
Guest Posted March 14, 2008 Share Posted March 14, 2008 Oh, you want to get the emailaddress using the username, I thought it was the other way around. Oh, then that should be pretty easy: // Your original code $username=$_SESSION['pwngame']; $getuser="SELECT * from eatyou_login where eatname='$username'"; $getuser2=mysql_query($getuser) or die("Could not get user"); //replaced with mysql_fetch_assoc $getuser3=mysql_fetch_assoc($getuser2); Now, assuming the field is called eatemail, it should be available via: $getuser3['eatemail'] Quote Link to comment Share on other sites More sharing options...
ricerocket Posted March 14, 2008 Author Share Posted March 14, 2008 wow thanks a million! I've been trying different things trying to get this to work for a long time. It works perfect just how I wanted it. 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.