Jump to content

Why (isset($_POST['submit'])) function not working?


tarunrathore

Recommended Posts

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 by tarunrathore
Link to comment
Share on other sites

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 by bakertaylor28
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.