0

Ok this is the code! I'm developing on phpstorm the problem is that everytime I hit submit the page refreshes but doesnt redirect or execute the echo with the variables!

Can someone please point any mistakes?

require_once "db.php";

$html = <<<TAG

<!DOCTYPE html>
<html>
<head>
<title>Log In</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<style>
html, body, .container {
    height: 100%;
}
.container {
    display: table;
    vertical-align: middle;
}
.vertical-center-row {
    display: table-cell;
    vertical-align: middle;
}
</style>

</head>

<body>

<div class="container">
    <div class="row vertical-center-row">
        <div class="col-lg-12">
            <div class="row">
                <div class="col-xs-4 col-xs-offset-4">
                <h3>Sign In</h3>
                <br>
                    <form action="login.php" method="post" role="form">
                    <div class="form-group">
                    <label for="name"> Name: </label>
                    <input class="form-control" name="name" value="Username" type="text" id="name">
                    </div>
                    <div class="form-group">
                    <label for="password"> Password:</label>
                    <input class="form-control" name="password" value="Password" type="password" id="password">
                    </div>
                    <button type="submit" class="btn btn-primary">Submit</button>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>


</body>


</html>
TAG;

echo $html;



if(isset($_POST['submit'])){

    $escapedName = mysqli_real_escape_string($_POST['name']);
    $escapedPW = mysqli_real_escape_string($_POST['password']);

    $testPW = hash('sha1', $escapedPW);

    echo $escapedName . $escapedPW;

    $sql = "select * from users where name ='$escapedName' and password='$testPW'";

    if($conn->query($sql)){

        header('location: /user.php');

    }

}
else{

    echo "se di ca ka";

}
kg_root
  • 45
  • 2
  • 10
  • Its possible that you have error reporting turned off so you cant see the error thats telling you that you cant use `header()` if you've already rendered anything to the user. Put `echo $html;` after your if else construct. – castis Jun 12 '15 at 16:18

1 Answers1

1

You are checking to see if a POST variable by the name of submit is set, but you aren't setting it. There is nothing named submit in your form, only an unnamed submit button. You need to add name="submit" to your submit button.

Change this:

<button type="submit" class="btn btn-primary">Submit</button>

With this:

<button type="submit" name="submit" class="btn btn-primary">Submit</button>
Kyle
  • 1,757
  • 1
  • 12
  • 22