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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.