The problem is, the username and password created in my database in any case, how to prevent this? I'm novice so I don't know much about PHP.
if (isset($_POST['username']) && isset($_POST['password']))
{
$username = $_POST["username"];
$password = $_POST["password"];
RegisterErrors($username , $password);
$query = "INSERT INTO users (Username,Password) VALUES ('{$username}','{$password}')";
$query_result = mysqli_query($connection , $query);
echo "added";
}
Here is the function to validate form registration :
function RegisterErrors($username , $password)
{
if (null == $_POST["username"] || null == $_POST["password"])
{
echo "username or password cant be empty";
return false;
}
if (empty($_POST["username"]) || empty($_POST["password"]))
{
echo "username or password cant be empty";
return false;
}
if (strlen($_POST["username"]) > 14)
{
echo "username must be less than 14 character";
return false;
}
if (strlen($_POST["password"]) < 6)
{
echo "password must be at least 6 character";
return false;
}
}