adv Posted May 4, 2008 Share Posted May 4, 2008 <?php if (isset($_POST['button'])) { $user = $_POST['user']; $pass = $_POST['pass']; $db = mysql_connect("localhost","root",""); mysql_select_db("users",$db); $rezz = mysql_query("select * from usrs where username = '$user' and password = PASSWORD('$pass')"); if (!$db ) { exit(mysql_error()); } if (mysql_num_rows($rezz) == "1") { echo "good"; } else { $errorMsg = "user/pass incorrect"; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form id="form1" name="form1" method="post" action="<?php $_SERVER['PHP_SELF']; ?>"> <label>username <input type="text" name="user" id="user" /> </label> <p> <label>password <input type="text" name="pass" id="pass" /> </label> </p> <p> <input type="submit" name="button" id="button" value="Submit" /> </p> </form> </body> </html> <?php if (isset($_POST['button'])) { if (mysql_num_rows($rezz) == "0") { echo $errorMsg; } } ?> in this code $rezz = mysql_query("select * from usrs where username = '$user' and password = PASSWORD('$pass')"); this doesn`t work if doesnt grab the pass from the database... it works if the password if uncrypted $rezz = mysql_query("select * from usrs where username = '$user' and password = '$pass' "); | adv1 | *B12E45A418E975B0269 | | adv2 | shit1 | second works what could be wrong in the database i have encripted the password with PASSWORD() function of sql Quote Link to comment https://forums.phpfreaks.com/topic/104014-solved-database-error/ Share on other sites More sharing options...
ablueycolor Posted May 4, 2008 Share Posted May 4, 2008 If the second one works then I would assume your password was never stored properly in the database and was stored as plaintext. I'd start by looking at your create user function. You could switch your queries to $sql = "select * from usrs where username = '$user' and password = PASSWORD('$pass')"; $rezz = mysql_query($sql); This way you can easily go into the function and do a: print($sql) to see if the mysql query is running properly. Quote Link to comment https://forums.phpfreaks.com/topic/104014-solved-database-error/#findComment-532493 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.