/    Sign up×
Community /Pin to ProfileBookmark

Storing Login Information???

I’ve begun to experiment with login systems using PHP and MySQL. What would be the correct way to retrieve someone’s username and password from the database, and then store it in variables?

[code=php]SELECT testusername FROM usernames
SELECT testpassword FROM passwords

$username = testusername;
$password = testpassword;
[/code]

Would that be correct?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMar 09.2008 — The first question would be, why do you want to retrieve the password? Normally you just need to verify that the username as password are correct, then you have no further need for the password.
[code=php]
$sql = "SELECT first_name FROM users WHERE username = '" .
mysql_real_escape_string($_POST['username']) . "' AND password = '" .
mysql_real_escape_string($_POST['password']) . "'";
$result = mysql_query($sql);
if(!$result)
{
// something wrong with the database or your query, so output an error
exit()
}
if(mysql_num_rows($result) != 1)
{
// invalid login, so output error or whatever you want to do.
exit();
}
// we're good to go
session_start();
$_SESSION['first_name'] = mysql_result($result, 0);
echo "Hello, {$_SESSION['first_name']}";
[/code]
Copy linkTweet thisAlerts:
@Joseph_WitchardauthorMar 09.2008 — All right, that clears it up for me. Thanks!
×

Success!

Help @Joseph_Witchard spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...