phpGod Posted March 18, 2007 Share Posted March 18, 2007 I just want to return the user_id number when the correct username and password is entered. If I comment out the AND pass=SHA('$p')) I can get it to work fine. Meaning when I just input the username it gives me the user_id number, but when I ask for the number with a password and ussername required instead, I get nothing. Any ideas? <?php if (isset($_POST['submitted'])) { require_once ('connect.php'); function escape_data ($data) { global $dbc; if (ini_get('magic_quotes_gpc')) { $data = stripslashes($data); } return mysql_real_escape_string(trim($data), $dbc); } // End of function. if (empty($_POST['username'])) { echo ('You forgot to enter a username.'); } else { $u = escape_data($_POST['username']); } if (empty($_POST['pass'])) { echo ('You forgot to enter your password.'); } else { $p = escape_data($_POST['pass']); } $query = "SELECT user_id FROM users WHERE (username='$u' AND pass=SHA('$p'))"; // ERROR HERE! $result = mysql_query ($query); $row = mysql_fetch_array($result); echo $row[0]; echo mysql_error(); } ?> <html> <head> </head> <body> <form action="logintest.php" method="post"> <p>Username: <input type="text" name="username" size="20" maxlength="30" /> </p> <p>Password: <input type="password" name="pass" size="20" maxlength="20" /></p> <p><input type="submit" name="submit" value="Login" /></p> <input type="hidden" name="submitted" value="TRUE" /> </body> </html> Link to comment https://forums.phpfreaks.com/topic/43290-solved-why-is-my-password-not-working/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.