I'm trying to echo registration system errors to the main index.php file, but I'm doing something wrong. Can someone please explain what I've been doing wrong and how to do it right?
index.php file.
<?php
session_start();
include "config.php";
?>
<div class="container">
<h1>Registration</h1>
<?php if(!empty($error)): ?>
<div class="alert alert-danger alert-dismissible">
<ul>
<li>
<?php echo $error; ?>
</li>
</ul>
</div>
<?php endif; ?>
<button class="close" data-dismiss="alert" aria-label="close">
<span aria-hidden="true">×</span>
</button>
<form action="main.php" method="post">
<p>Username: </p>
<p><input type="text" name="username" autocomplete="off"></p>
<p>Password: </p>
<p><input type="password" name="password" autocomplete="off"></p>
<p><button name="send" class="btn btn-primary" id="btn">Send</button></p>
</form>
</div>
</div>
main.php file..
<?php
include "config.php";
if(isset($_POST['send'])) {
$username = $_POST['username'];
$password = $_POST(md5['password']);
if(empty($_POST['username'])) {
$error = "Username is empty<br/>";
}
if(empty($_POST['password'])) {
$error = "Password is empty";
}
$query = mysqli_query($connect,"INSERT INTO register(username,password) VALUES('$username', '$password')")
or die(mysql_error());
echo "Registred";
}
$_SESSION['error'] = $error;
?>