I can use the password() function fine to enter a password into MySQL table, it's retrieving it that's the problem. I'm using the exact code out of a PHP book and I just can't get the darn thing to work. Am i right in presuming that if you set $pass = PASSWORD(mypassword) that MySQL encrypts it and then to unencrypt it you just do the same? ie. $pass = PASSWORD($password) (where $password is the value entered into the login form?
Here's the code:
<?
session_start();
if ($op == "ds") {
$connection = @mysql_connect("localhost", "admin", "gorillaz") or die("Couldn't connect.");
$db = mysql_select_db("neaDB", $connection) or die("Couldn't select database.");
$sql = "SELECT * FROM user WHERE username = \"$username\" AND password = PASSWORD(\"$password\")";
$result = @mysql_query($sql, $connection) or die("Couldn't execute query.");
while ($row = mysql_fetch_array($result)) {
$username = $row[username];
$password = $row[password];
}
$num = mysql_numrows($result);
if ($num != "0") {
session_register('valid');
$HTTP_SESSION_VARS[valid] = "yes";
$show_menu = "yes";
} else {
$msg = "Bad Login. Please try again.";
$show_menu = "no";
}
} else {
if ($HTTP_SESSION_VARS[valid] == "yes") {
$show_menu = "yes";
} else {
$show_menu = "no";
}
}
?>
i've also tried adding: echo "$username $password";
just to see if it's working at all, and it's the encrypted password that is echoed not the unencrypted one.
please help me!!!