chrisbasnett Posted March 16, 2009 Share Posted March 16, 2009 Right, lil script to re-encrypt a users password on a login page and compare it to that saved within a database. For some reason script doesn't seem to be working and i'm lacking in ideas on how to solve, any help would be appreciated. Register.php <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("DB1", $con); $user = strip_tags(substr($_POST['users_user'],0,32)); $pw = strip_tags(substr($_POST['users_password'],0,32)); $pw2 = strip_tags(substr($_POST['pw2'],0,32)); $cleanpw = crypt(md5($pw),md5($user)); $sql = "insert into users (users_username,users_password, users_Email) values('".mysql_real_escape_string($user)."','".mysql_real_escape_string($cleanpw)."','$_POST[users_email]')"; if ($pw==$pw2) { if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "User added, you may now login"; } else echo "Error Passwords Do not match, please try again"; mysql_close($con) ?> Note:Above script works, just a bit of background Logincheck.php <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("db1", $con); $user = strip_tags(substr($_POST['users_username'],0,32)); $pw = strip_tags(substr($_POST['users_password'],0,32)); $cleanpw = crypt(md5($pw),md5($user)); $sql = "select users_username, users_password from users where users_username='". mysql_real_escape_string($user)."' and users_username='". mysql_real_escape_string($cleanpw)."' limit 1'"; $result = mysql_query($sql); if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } if (mysql_num_rows($result)){ echo "User found"; }else{ echo "User not found"; } ?> The issue seems to be around the sql query itself. The script after a bit of editing seems to work but fails to find the requested data when even after a manual check is in the database correctly. Any help would be much appreciated. Chris Quote Link to comment Share on other sites More sharing options...
suma237 Posted March 16, 2009 Share Posted March 16, 2009 check the connection is working properly or not? echo the select statement and check it with database. Quote Link to comment 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.