manch889 Posted October 22, 2020 Share Posted October 22, 2020 <?php require 'config.php'; if (isset($_POST['login'])) { $password = mysqli_real_escape_string($con, $_POST['tpw']); $username= mysqli_real_escape_string($con, $_POST['username']); $query = "SELECT * FROM tinfo WHERE username='$username' AND password='$password'"; $results = mysqli_query($con, $query); if (mysqli_num_rows($results) == 1) { $_SESSION['username'] = $username; $_SESSION['success'] = "You are now logged in"; header('location: ../html/register.html'); }else { echo "Wrong username/password combination"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/311625-index-undefined/ Share on other sites More sharing options...
cyberRobot Posted October 22, 2020 Share Posted October 22, 2020 (edited) Which "index" does the error message refer to? What is the error message? Side note: if you're not doing so already, you'll want to look into password security. More information can be found here:https://www.php.net/manual/en/faq.passwords.php Edited October 22, 2020 by cyberRobot 1 Quote Link to comment https://forums.phpfreaks.com/topic/311625-index-undefined/#findComment-1581998 Share on other sites More sharing options...
manch889 Posted October 22, 2020 Author Share Posted October 22, 2020 Notice: Undefined index: username in C:\xampp\htdocs\IWT Assigment - Copy\php\tlogin.php on line 6 Quote Link to comment https://forums.phpfreaks.com/topic/311625-index-undefined/#findComment-1581999 Share on other sites More sharing options...
cyberRobot Posted October 22, 2020 Share Posted October 22, 2020 What does your form code look like? 1 Quote Link to comment https://forums.phpfreaks.com/topic/311625-index-undefined/#findComment-1582000 Share on other sites More sharing options...
manch889 Posted October 22, 2020 Author Share Posted October 22, 2020 <form method="post" action="../php/tlogin.php" name="form" onsubmit="return validated()" ><br></br> <lable> Username</lable> <input type="text" placeholder="Enter Username" name="username" id="uname" required> <div id="uname_error">Please Fill Up your Username</div> <br></br> <lable>Password</lable> <input type="password" placeholder="Enter Password" name="tpw" id="tpw" required><br></br> <div id="pass_error">Please Fill Up your Password</div> <br></br> <button type="Submit" name="login">Login</button><br></br> <a href="#">Lost Your Password?</a><br> <a href="#">Don't have an account?</a> </form> Quote Link to comment https://forums.phpfreaks.com/topic/311625-index-undefined/#findComment-1582001 Share on other sites More sharing options...
cyberRobot Posted October 22, 2020 Share Posted October 22, 2020 Try adding the following echo statement inside your if construct to see what $_POST contains: if (isset($_POST['login'])) { echo '<pre>' . print_r($_POST, true) . '</pre>'; After adding the line, try submitting the form, but don't use a real login. Just enter random characters. What does the output look like? Note that you're looking for output like the following (please don't post real usernames/passwords): Array ( [tpw] => sdflaje ... ) Quote Link to comment https://forums.phpfreaks.com/topic/311625-index-undefined/#findComment-1582002 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.