I'm new to PHP and I'm trying to create a simple register page. I made two separate files for HTML and PHP. So in post method I include this second file like this: <form action="register.php" method="post">
. The problem is after submitting registration I want to check all this columns and if are wrong, put some information about it. But everything opens in a new blank page. I want to maintain PHP and HTML in separate files. Index.php:
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel = "stylesheet" type = "text/css" href = "main.css">
<link href="https://fonts.googleapis.com/css?family=Lato:400,700"
rel="stylesheet">
<link rel="stylesheet"
href="https://use.fontawesome.com/releases/v5.0.13/css/all.css"
integrity="sha384-
DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp"
crossorigin="anonymous">
<title> Rejestracja</title>
</head>
<body>
<div id = "imover">
<nav><div id = "navcontainer"><ul>
<li><a href = "#">Home</a></li>
<li><a href = "#">About us</a></li>
<li><a href = "#">Our projects</a></li>
<li><a href = "#">Contact</a></li>
</ul></div></nav>
<div id = "socialscontainer"><div id = "fb"><a href = "#"><i class="fab
fa-facebook-square"></i></a></div><div id = "tw"><a href = "#"><i class="fab
fa-twitter-square"></i></a>
</div><div style = "clear: both;"></div>
</div>
<header><div id = "logocontainer"><h1>Register</h1></div></header>
<div id = "container">
<form action="register.php" method="post">
<h2>Username</h2><input type = "text" name = "username">
<h2>Password</h2><input type = "password" name = "pass1">
<h2>Confirm password</h2><input type = "password" name = "pass2">
<h2>E-Mail</h2><input type = "text" name = "email">
<br/><br/>
<input type = "submit" id ="btn" value="Register now!">
</form>
</div>
<span><a href = "logowanie.php">Do you have an account? Log in
now!</a></span>
</div>
</body>
</html>
And there's register.php:
<?php
session_start();
$username = $_POST['username'];
$password = $_POST['pass1'];
if($_POST['pass2'] !=$password) {header("Location: mistake.php"); exit();}
$hashed_password = password_hash($password,PASSWORD_DEFAULT);
$email = $_POST['email'];
echo $username;
?>