Jump to content

php and databases. Need help


ricerocket

Recommended Posts

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

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.

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?

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']

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.