tarunrathore Posted September 9, 2020 Share Posted September 9, 2020 (edited) I have a simple log in form. By debugging I found that isset post submit function is not responding. It remains on the same page after submitting form. I have googled all the possible solutions to this problem but none worked. Any help is greatly appreciated. The form is in multiplelogin.php file and the code is in multi.php file. After login redirection is to teachers.php file. <?php session_start(); $conn = mysqli_connect("localhost", "root", "", "signup"); if(isset($_SESSION['username'])) { header('location: teachers.php'); exit(); } ?> <!DOCTYPE html> <head> <link rel="stylesheet" type="text/css" href="bootstrap.css"> <title> Teachers Students Login </title> </head> <body class="bg-secondary"> <div class="container"> <div class="row justify-content-center"> <div class="col-log-5 bg-light mt-5 px-0"> <h3 class="text-center text-light bg-primary py-3 px-5"> Log In </h3> <?php if(isset($_GET['error'])) { if ($_GET['error'] == 'invalidemail') { echo "<p class='alert'> Invalid Email Id! </p>"; } else if ($_GET['error'] == 'wrongpassword') { echo "<p class='alert'> Incorrect Password! </p>"; } } ?> <form action="multi.php" action="post" class="py-4 px-5" id="form"> <div class="form-group px-5"> <input type="email" name="email" class="form-control form-control-lg" placeholder="Email" required> </div> <div class="form-group px-5"> <input type="password" name="password" class="form-control form-control-lg" placeholder="Password" required> </div> <div class="form-group px-5"> <input type="submit" name="submit" value="Submit" class="btn btn-primary btn-block"> </div> </form> </div> </div> </div> </body> </html> <?php ini_set( 'display_errors', 1 ); error_reporting( E_ALL ); if (isset($_POST['submit'])) { $conn = mysqli_connect("localhost", "root", "", "signup"); $email = $_POST['email']; $password = $_POST['password']; $sql = "SELECT * FROM teachersRegist WHERE email=?"; $stmt = mysqli_stmt_init($conn); if (!mysqli_stmt_prepare($stmt, $sql)) { header("Location: multilogin.php?error=sqlerror"); exit(); } else { mysqli_stmt_bind_param($stmt, "s", $email); mysqli_stmt_execute($stmt); $result = mysqli_stmt_get_result($stmt); if ($row = mysqli_fetch_assoc($result)) { $pwdCheck = password_verify($password, $row['password']); if ($pwdCheck == false) { header("Location: multilogin.php?error=wrongpassword"); exit(); } else if ($pwdCheck == true) { session_start(); $_SESSION['username'] = $row['username']; $_SESSION['email'] = $row['email']; header("Location: teachers.php?login=success"); exit (); } else { header("Location: multilogin.php?error=wrongpassword"); exit(); } } else { header("Location: multilogin.php?error=invalidemail"); exit(); } } } else { header("Location: multilogin.php"); exit(); } ?> Edited September 9, 2020 by tarunrathore Quote Link to comment https://forums.phpfreaks.com/topic/311449-why-isset_postsubmit-function-not-working/ Share on other sites More sharing options...
requinix Posted September 9, 2020 Share Posted September 9, 2020 <form action="multi.php" action="post" class="py-4 px-5" id="form"> Take a closer look at that. If you don't see a problem, try reading each piece of it aloud to yourself. Quote Link to comment https://forums.phpfreaks.com/topic/311449-why-isset_postsubmit-function-not-working/#findComment-1581246 Share on other sites More sharing options...
bakertaylor28 Posted September 9, 2020 Share Posted September 9, 2020 (edited) 19 hours ago, requinix said: <form action="multi.php" action="post" class="py-4 px-5" id="form"> Take a closer look at that. If you don't see a problem, try reading each piece of it aloud to yourself. This should be <form action="/multi.php" ...> because, assuming multi.php is in the root directory of the server, you need the forward slash to denote any address that is on the resident server and is not a GET Request via http. If it is in a subdirectory, it will be action="/path/to/file.php" Edited September 10, 2020 by bakertaylor28 Quote Link to comment https://forums.phpfreaks.com/topic/311449-why-isset_postsubmit-function-not-working/#findComment-1581261 Share on other sites More sharing options...
requinix Posted September 10, 2020 Share Posted September 10, 2020 55 minutes ago, bakertaylor28 said: This should be <form action="/multi.php" ...> because, assuming multi.php is in the root directory of the server, you need the forward slash to denote any address that is on the resident server and is not a GET Request via http. If it is in a subdirectory, it will be action="/path/to/file.php" Sorry but no. The slash affects the URL, naturally, but it is by no means necessary for the form to work. Nor does it have anything to do with GET vs. POST. Quote Link to comment https://forums.phpfreaks.com/topic/311449-why-isset_postsubmit-function-not-working/#findComment-1581262 Share on other sites More sharing options...
benanamen Posted September 10, 2020 Share Posted September 10, 2020 Quote Link to comment https://forums.phpfreaks.com/topic/311449-why-isset_postsubmit-function-not-working/#findComment-1581263 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.