pals, got a quite disgusting situation here with my submit form. So, the problem: once user submits form his data goes to database and THEN if he refreshes the page the form submits again and he can do it infinite times and my DB will be full of useless data. So, how to prevent form submition after f5? I tried to use header('Location: success.php');
, but it doesn't help. Here is my server.php code:
<?php
session_start();
$message = "Wrong input";
$username = "";
$email = "";
$errors = array();
$db = mysqli_connect('localhost', 'root', 'root', 'example');
if(isset($_POST['register'])) {
$username = mysqli_real_escape_string($db, $_POST['username']);
$email = mysqli_real_escape_string($db, $_POST['email']);
$password = mysqli_real_escape_string($db, $_POST['password']);
if(empty($username) || empty($email) || empty($password)) {
echo "<script type='text/javascript'> alert('$message');</script>";
array_push($errors, "err");
}
}
if(count($errors) == 0) {
$pass = md5($password);
$query = "INSERT INTO users (username, email, password) VALUES ('$username', '$email', '$pass')";
mysqli_query($db, $query);
header('Location: success.php');
}
?>