I read a bit about the Post/Redirect/Get pattern and I'm not really sure how to apply it in PHP. Could someone please take this very simple example and explain it to me? Let's say you have a form and a user needs to register. After that he just gets redirected to another page. How do I make that so that it prevents adding duplicate content in the Database.
My Form
<form id="registerPage" method="POST" action="reg.php">
<input id="username" name="username" type="text" placholder="username">
<input id="password" name="password" type="password" placholder="password">
<button type="submit">Register</button>
</form>
reg.php
<?php
$username = $_POST['username'];
$password= $_POST['password'];
$encrypt= md5($password);
$con = mysqli_connect("localhost","yo","sup","cool");
$query = "INSERT INTO table(";
$query .= "username,";
$query .= "password)VALUES(";
$query .= "'$username',";
$query .= "'$password')";
mysqli_query($con,$query);
echo "<script>alert('Successfully Registered')</script>";
mysqli_close($con);
?>