fragman44 Posted January 15, 2008 Share Posted January 15, 2008 hello i am pretty new to php and mySQL and im sorry but i do not know what version of mysql i am using. i am trying to retrieve the login info from a form that forwards the data to the page and compares it against the mySQL database. for some reason it will only say wrong password =[ sorry if i havent given enough info but im very new. <?php if(isset($_POST['login'])) { $db_host = "localhost"; $db_user = "root"; $db_pwd = "thePass"; $db_name = "namestorage"; mysql_connect($db_host, $db_user, $db_pwd); mysql_select_db($db_name) or die(mysql_error()); $username = $_POST['username1']; $password = $_POST['password1']; $ress=mysql_query("SELECT * FROM storagedata WHERE username='".$usernames."' AND password='".$passwords."'") or die(mysql_error()); $rows=mysql_fetch_array($ress); if(($rows["username"]==$username)&&($rows["password"]==$password)) { echo "logged in"; }else { echo "Incorrect Password or Username"; } } ?> Link to comment https://forums.phpfreaks.com/topic/86084-login-from-mysql-database/ Share on other sites More sharing options...
toplay Posted January 15, 2008 Share Posted January 15, 2008 You're using $usernames (plural) here: ...username='".$usernames."' AND ... And only using $username (singular) here: ...$rows["username"]==$username)&&(... Same problem with $passwords and $password. Modify the query to use the singular variable names. FYI - There's no reason to do the exact check in PHP "if" statement because you're already doing the same thing in the SQL query itself. Just do after the fetch: if ($rows) { echo "logged in"; } else ... Link to comment https://forums.phpfreaks.com/topic/86084-login-from-mysql-database/#findComment-439581 Share on other sites More sharing options...
fragman44 Posted January 15, 2008 Author Share Posted January 15, 2008 well i re-did the whole database and changed the code around to the best i could but still no luck.. <?php if(isset($_POST['login'])) { $db_host = "localhost"; $db_user = "root"; $db_pwd = "steveosb"; $db_name = "logins"; mysql_connect($db_host, $db_user, $db_pwd); mysql_select_db($db_name) or die(mysql_error()); $username = $_POST['username1']; $password = $_POST['password1']; $ress=mysql_query(" SELECT * FROM users WHERE username='$username' AND password='$password' ") or die(mysql_error()); if ($rows=mysql_fetch_array($ress)){ echo "logged in"; }else { echo "Incorrect Password or Username"; } } ?> Link to comment https://forums.phpfreaks.com/topic/86084-login-from-mysql-database/#findComment-439588 Share on other sites More sharing options...
toplay Posted January 15, 2008 Share Posted January 15, 2008 Double check your form is a POST and has the names: login, username1, and password1 Display the query: $sql = "SELECT * FROM `users` WHERE `username` = '$username' AND `password` = '$password'"; echo $sql; $ress=mysql_query($sql) or die... Link to comment https://forums.phpfreaks.com/topic/86084-login-from-mysql-database/#findComment-439592 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.