I am working to a register login page with php and html. But my php code cannot see the data sent from php. Down are my html and php files.
<html>
<head>
<meta charset="utf-8">
<link href = '../css/login.css' rel = 'stylesheet'>
<title> Login </title>
</head>
<body>
<form action="../php/login.php" method="post">
<input id = "loginButton" type="image" src ="../images/loginAndRegister.gif" alt="submit">
<div class = "panel">
<p> Login </p>
<br>
<br>
<label> username </label>
<br>
<input type = "text" name = "username" required>
<br>
<label> password </label>
<br>
<input type = "password" name = "password" required>
<br>
</div>
</form>
</body>
</html>
<html>
<body>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "dark_souls";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$user = isset($_POST['username']) ? $_POST['username'] : NULL;
$pass = isset($_POST['password']) ? $_POST['password'] : NULL;
echo $user;
$sql = "SELECT * FROM users WHERE username = '".$user."' AND password = '".$pass."'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
header("Location: ../templates/Home.html");
} else {
echo "Wrong Credentials";
}
?>
</body>
</html>
I have writted that "echo $user" in the php code just to check if it is working. The problem is that I used EXACTLY the same code for register ant there it worked. Help please!