Okay,
if the register request is sent to another script you have to redirect the client back to a page that can accept GET requests. Which can be the sign in page or the sign up in case the registration failed. So at the end of the script, right after mysqli_close() you would write:
header('Location: http://site/login');
exit;
You could work on the statements to define the header location string and redirect the user to the appropriated page, depending on the results, for example:
<?php
# use session to save the error message
session_start();
if($_SERVER['REQUEST_METHOD']=='POST')
{
include 'DatabaseConfig.php';
# default location
$location = 'Location: http://site/sign_in';
# default message
$_SESSION['msg'] = 'Registration Successfully.';
$con = mysqli_connect($localhost,$username,$password,$database);
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
$CheckSQL = "SELECT * FROM users WHERE email='$email'";
$check = mysqli_fetch_array(mysqli_query($con,$CheckSQL));
if(isset($check))
{
$_SESSION['msg'] = 'Email Already Exist.';
$location = 'Location: http://site/sign_up';
}
else
{
$Sql_Query = "INSERT INTO users (username,password,email) values ('$username','$password','$email')";
if( ! mysqli_query($con,$Sql_Query))
{
$_SESSION['msg'] = 'Something went wrong.';
$location = 'Location: http://site/sign_up';
}
}
mysqli_close($con);
header($location);
# exit to force the redirect
exit;
}
Then on the landing pages you start the session again, get the message if it exists and unset, so that next request does not carry the old message:
<?php
# initialize the session
session_start();
# initialize the variable
$msg = '';
if(TRUE === array_key_exists('msg', $_SESSION))
{
$msg = $_SESSION['msg'];
unset($_SESSION['msg']);
}
# print the message where needed...
What you still need to do, as suggested by Diafol, is to …