XCalibre3 Posted May 2, 2023 Share Posted May 2, 2023 (edited) <!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title>Login</title> <link rel="stylesheet" href="style.css"/> </head> <body> <?php mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); $servername = "localhost"; $username = "root"; $password = ""; $dbname = "calendar"; $conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } session_start(); if (isset($_POST['submit '])) { $email=$_POST['username']; $password=$_POST['password']; $stmt = $mysqli->prepare("SELECT username,password FROM `admins` WHERE (username=? AND password=?)"); $stmt->bind_param('ss',$username,$password); $stmt->execute(); $stmt->bind_result($username,$password); $rs= $stmt->fetch (); if (!$rs) { echo "<div class='form'> <h3>Incorrect Username/password.</h3><br/> <p class='link'>Click here to <a href='login.php'>Login</a> again.</p> </div>"; } else { $_SESSION['username']=$username; header('location:welcome.php'); } } else { ?> <form class="form" method="post" name="login"> <h1 class="login-title">Login</h1> <input type="text" class="login-input" name="username" placeholder="Username" autofocus="true"/> <input type="password" class="login-input" name="password" placeholder="Password"/> <input type="submit" value="Login" name="submit" class="login-button"/> <p class="link"><a href="registration.php">New Registration</a></p> </form> <?php } ?> </body> </html> Edited May 2, 2023 by XCalibre3 Quote Link to comment Share on other sites More sharing options...
Barand Posted May 2, 2023 Share Posted May 2, 2023 Is your query definitely finding a matching record? Quote Link to comment Share on other sites More sharing options...
maxxd Posted May 2, 2023 Share Posted May 2, 2023 I should hope you hash the password value before putting it into the database - right now you're doing a plain-text compare. Also, is the name of your submit button actually 'submit ' (note the space at the end). Are you getting an error message or is the script just always showing the login form? Perhaps using a few words to describe what's happening would help us to help you. 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.