1

I was having trouble with getting my login form to redirect to user home page since last night, after one successful attempt. After filling the form, I would press submit but I remained on the same page, except the form would be cleared. So i decided to echo my inputs using the $_POST method, and after resubmitting the form, I saw that the page displayed 1 for both the entries. What is wrong in my code?

<!DOCTYPE html>

<?php require_once("../Includes/Session.php"); ?>
<?php require_once("../Includes/DB_Connection.php"); ?>
<?php require_once("../Includes/Functions.php"); ?>
<?php require_once("../Includes/Validation_Functions.php"); ?>

<head> 

<title> eTransport: Login</title>

<link rel="stylesheet" type="text/css" href="Login_Style.css">
</head>

<html> 
<body>
<div class="div1">
    <h1 class="title"> Online eTransport Service (Fiji) </h1>

    <div>
    <form action="Login.php" method="POST">
        eTransport_ID: <input type="text" name="eTransport_ID"><br>
        Password: <input type="password" name="Password"><br>
        <input type="submit" name="Submit" value="submit"><br>
        <?php echo isset($_POST['eTransport_ID']); ?><br>
        <?php echo isset($_POST['Password']); ?>
    </form>
    </div>
</div>
</body>
</html>

<?php

$id = isset($_POST['eTransport_ID']);
$password = isset($_POST['Password']);

$checked_id= mysql_prep($id);

$query = "SELECT eTransport_ID ,Password FROM etrans_id_details";

$login_set = mysqli_query($conn, $query);


while ($row = mysqli_fetch_assoc($login_set)){
    if ($checked_id == $row["eTransport_ID"] AND $password == $row["Password"]){
        redirect_to("Home.php");
    }
}

?>

The Output for my Code with $_POST:

img

4
  • 1
    You're storing the result of isset in $id and $password -- not the actual ID and password Commented Nov 16, 2017 at 2:23
  • it's displaying 1 because that you're using isset(). 1 = true in that sense. The variables are set. Commented Nov 16, 2017 at 2:23
  • Have a look php.net/manual/en/function.isset.php Commented Nov 16, 2017 at 2:23
  • I only added isset() since the browser gave 2 errors under the form as undefined index. how do I remove that? Commented Nov 16, 2017 at 2:31

1 Answer 1

1

Here's the long answer. Replace $id = isset($_POST['eTransport_ID']); $password = isset($_POST['Password']);

with

$id = $_POST['eTransport_ID']; $password = $_POST['Password']; and add code to test if it is set.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, this worked, but upon reloading the Login page, it displays 2 errors saying undefined index. How do I remmove that?
you need to put test to see if the variable is set so if ($id == '') die(0); and one for the other.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.