Im trying to create a simple login page, this is what I have so far in my Login.php
Link for the codepaste if it is hard to understand HERE
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="description" content="$1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="style.css">
<title>test</title>
<?php
include_once 'dbConfig.php';
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
?>
<h1 class="h1">Login</h1>
</head>
<?php
if(isset($_POST['login'])){
$stmt = $mysqli->prepare("SELECT id FROM users WHERE username=? AND password=?");
$stmt-> bind_param("ss", $username, $password);
$username = $_POST["username"];
$password = $_POST["password"];
$stmt->execute();
if($stmt->execute == true){
header("Location: http://localhost/test2/Home.php");
}
}
?>
<body>
<form method="post" id="registerForm">
<label id="first"> Username</label><br/>
<input type="text" required name="username"><br/>
<br/>
<label id="first">Password</label><br/>
<input type="password" required name="password"><br/>
<br/>
<input type="submit" value="Sign in" name="login"/>
</body>
</html>
I am aware that this code has security flaws and Im going to improve it once the basic functionality will be working. Problem: When I click login button, nothing happens, im not redirected even if I don't check if the login was success.
$POST['login']
IT would be$_POST['login']
plus not able to see your connection and include any file for connectionif($stmt->execute == true)
which was my way of checking if it was a success. Maybe there is a better way to do this? EDIT my connection filedbConfig.php
is included on line 14. It has the connection string and this is where$mysqli
variable comes from.$stmt->num_rows
to check weather your query return result ot not