user8292028
user8292028

Reputation:

Link a php page to another php page

I am trying to link a make a login page using php without database but the link to the other page is not working . It is staying on the same page. No error message also.

Here is the php part of the code:

<?php
    $error = "";

if(isset($_POST['MRDlogin']))
{
    if(isset($_POST['username'],$_POST['password'])){

        /*** You can change username & password ***/
        $user = array(
                        "user" => "MRD",
                        "pass"=>"msit"          
                );
        $username = $_POST['username'];
        $pass = $_POST['password'];
        if($username == $user['user'] && $pass == $user['pass']){

            header("Location: http://localhost/portal/MRD.php");
        }else{
            $error = '<div class="alert alert-danger">Invalid Login</div>';
        }
    }
}

and my html form part is:

> <div class="panel-body">
>                     <?php echo $error; ?>
>                     <form accept-charset="UTF-8" role="form" method="post">
>                         <fieldset>
>                             <div class="form-group">
>                                 <input class="form-control" placeholder="Username" name="username" type="text">
>                             </div>
>                             <div class="form-group">
>                                 <input class="form-control" placeholder="Password" name="password" type="password" value="">
>                             </div>
>                                 <input class="btn btn-lg btn-success btn-block" type="submit" value="Login">
>                         </fieldset>
>                     </form>
>                 </div>

Upvotes: 0

Views: 3382

Answers (2)

Donnicias
Donnicias

Reputation: 186

The following variable cannot be found

$_POST['MRDlogin']

Add it in you button as shown below

 <div class="panel-body">
                 <?php echo $error; ?>
                 <form accept-charset="UTF-8" action="page.php" role="form" method="post">
                     <fieldset>
                         <div class="form-group">
                             <input class="form-control" placeholder="Username" name="username" type="text">
                         </div>
                         <div class="form-group">
                             <input class="form-control" placeholder="Password" name="password" type="password" value="">
                         </div>
                             <input class="btn btn-lg btn-success btn-block" type="submit" value="Login" name="MRDlogin">
                     </fieldset>
                 </form>

Upvotes: 1

dion
dion

Reputation: 35

in form tag add action tag with value of page name that will process submited form:

<form action="page.php" accept-charset="UTF-8" role="form" method="post">

Upvotes: 0

Related Questions