omega1983 Posted September 29, 2020 Share Posted September 29, 2020 <?php //check for required fields from the form if ((!$_POST['username']) || (!$_POST['password'])) { header("Location: auth1.php"); //header("Location: auth1.php"); exit; //set authorization cookie $servername = "localhost"; $username = "tmc_user50"; $password = "Atl_344"; // Create connection $conn = mysqli_connect($servername, $username, $password); $message=""; if(count($_POST)>0) { $conn = mysqli_connect("localhost","tmc_user50","Atl_344"); $result = mysqli_query($conn,"SELECT * FROM admin2 WHERE username='" . $_POST["username"] . "' and password = '". $_POST["password"]."'"); $count = mysqli_num_rows($result); if($count==0) { $message = "Invalid Username or Password!"; } else { $message = "You are successfully authenticated!"; } } } ?> When I enter any username ad password the code from auth2.php (the code above allows a connection anyway) I am attempting to redirect users back to auth1 if there is an incorrect username or password Quote Link to comment https://forums.phpfreaks.com/topic/311542-login-script-not-authenticating/ Share on other sites More sharing options...
Barand Posted September 29, 2020 Share Posted September 29, 2020 Define "allows a connection" Quote Link to comment https://forums.phpfreaks.com/topic/311542-login-script-not-authenticating/#findComment-1581643 Share on other sites More sharing options...
benanamen Posted September 29, 2020 Share Posted September 29, 2020 (edited) So little code yet so much wrong. DO NOT USE PLAIN TEXT PASSWORDS. NOT NOW, NOT EVER! Use Prepared Statements - NEVER EVER put variables in your query. Do not SELECT *. Specify the column names you want You need to check the REQUEST METHOD, not count the POST array You have an extra closing curly bracket Do not post your database login credentials for the whole world to see Edited September 29, 2020 by benanamen Quote Link to comment https://forums.phpfreaks.com/topic/311542-login-script-not-authenticating/#findComment-1581644 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.