Reaper0167 Posted January 1, 2009 Share Posted January 1, 2009 if your username is not in the database,, the error comes up saying that your not registered. but for the usernames that i know are in the database, it won't take me to the success page. <?php // server and database variable information $host = "----------"; $username = "-----------"; $password = "------------"; $db_name = "----------"; $tbl_name = "-----------"; // connects to server and database mysql_connect("$host", "$username", "$password") or die("Could not connect."); mysql_select_db("$db_name") or die("Could not find database"); // username and password sent from form $username = $_POST['username']; $password = $_POST['password']; // protect MySQL injection $username = stripslashes($username); $password = stripslashes($password); $username = mysql_real_escape_string($username); $password = mysql_real_escape_string($password); // check username and password $sql = "SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result = mysql_query($sql); // Mysql_num_row is counting table row $count = mysql_num_rows($result); // sending user to homepage or giving them log in error if ($count == 1) { header("location: home.php"); //echo "You are now logged in."; //$message = "You are now logged in."; //header("location: index.php?error=" . urlencode($message)); } else { //echo "This username is not registered. Please register first."; $message = "This username is not registered. Pleaser register first."; header("location: index.php?error=" . urlencode($message)); } ?> Link to comment https://forums.phpfreaks.com/topic/139095-solved-lol-now-my-login-script-stopped-working/ Share on other sites More sharing options...
revraz Posted January 1, 2009 Share Posted January 1, 2009 Maybe because you use two different variables? $username = mysql_real_escape_string($username); $password = mysql_real_escape_string($password); $sql = "SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; Either use $myusername or $username for both, same with $mypassword and $password. Link to comment https://forums.phpfreaks.com/topic/139095-solved-lol-now-my-login-script-stopped-working/#findComment-727494 Share on other sites More sharing options...
Reaper0167 Posted January 1, 2009 Author Share Posted January 1, 2009 ooppss,,, thanks,,, i thought i changed all of them,,, thanks again. Link to comment https://forums.phpfreaks.com/topic/139095-solved-lol-now-my-login-script-stopped-working/#findComment-727502 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.