silverglade Posted September 2, 2011 Share Posted September 2, 2011 Hi, I am trying to make a login script that uses the user's id from the database, and tries to match it up with the user and password sent by the login form. My checklogin.php page, just jumps back to the index.php page for some reason. I don't know why. I get the following errors, any help greatly appreciated. thank you. Notice: Undefined index: myusername in /hermes/bosweb/web173/b1739/public_htmlchecklogin.php on line 19 Notice: Undefined index: mypassword in /hermes/bosweb/web173/b1739/public_html/checklogin.php on line 20 Wrong Username or Password Here is my code to check the id. I can't figure out what is wrong. <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); $host = ""; $database = ""; $username = ""; $password = ""; $tbl_name = "users"; $conn = mysql_connect($host, $username, $password) or die("Could not connect: " . mysql_error()); if($conn) { mysql_select_db($database); } else { echo "failed to select database"; } // username and password sent from form $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT id FROM $tbl_name WHERE username='$myusername' and password= SHA1('$mypassword')"; $result=mysql_query($sql); $query_data = mysql_fetch_row($result); // Mysql_num_row is counting table row $count=mysql_num_rows($result) ; // If result matched id, table row must be 1 row if($count==1){ session_start(); $_SESSION['userid']=$query_data[0]; header("location:login_success.php"); } else { echo "Wrong Username or Password"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/246301-login-script-not-getting-id/ Share on other sites More sharing options...
KevinM1 Posted September 2, 2011 Share Posted September 2, 2011 It's telling you that there are no POST keys named 'myusername' and 'mypassword'. Check your form to make sure your inputs have the right names. Quote Link to comment https://forums.phpfreaks.com/topic/246301-login-script-not-getting-id/#findComment-1264884 Share on other sites More sharing options...
silverglade Posted September 2, 2011 Author Share Posted September 2, 2011 Awesome, thank you so much!! It works. It's alive! muwahah. thank you. :-* Also, does anyone know if I should do the "password reset by email" script now, or the "access levels" for the accounts now instead? I am not sure which one to do. Any advice greatly appreciated. thanks. Quote Link to comment https://forums.phpfreaks.com/topic/246301-login-script-not-getting-id/#findComment-1264888 Share on other sites More sharing options...
silverglade Posted September 2, 2011 Author Share Posted September 2, 2011 Nevermind I am going to do the reset password first. Quote Link to comment https://forums.phpfreaks.com/topic/246301-login-script-not-getting-id/#findComment-1264896 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.