I am not sure what it is but my code will not insert into my database, I’ve tried changing the code a 100 ways but I am still learning this new stuff. Probably a simple fix but if you know your help would be appreciated.
<?php
$Username = mysqli_real_escape_string(strip_tags(stripslashes($_POST['_Username'])));
$Password = mysqli_real_escape_string(strip_tags(stripslashes($_POST['_Password'])));
$ConfirmPassword = mysqli_real_escape_string(strip_tags(stripslashes($_POST['_ConfirmPassword'])));
$Email = mysqli_real_escape_string(strip_tags(stripslashes($_POST['_Email'])));
$Submit = mysqli_real_escape_string(strip_tags(stripslashes($_POST['_Submit'])));
function is_alphanumeric($Username) {
return (bool)preg_match("/^([a-zA-Z0-9])+$/i", $Username);
}
if ($Submit) {
$Username = filter($Username);
if (!$Username||!$Password||!$ConfirmPassword) {
echo "<b>Please fill in all required fields.</b>";
} else {
$userExist = mysqli_query("SELECT * FROM Users WHERE Username='$Username'");
$userExist = mysqli_num_rows($userExist);
$userExist1 = mysqli_query("SELECT * FROM Users WHERE OriginalName='$Username'");
$userExist1 = mysqli_num_rows($userExist1);
if ($userExist > 0) {
echo "<div id='Error'>That username already exists.</div>";
} elseif ($userExist1 > 0) {
echo "<div id='Error'>That username already exists.</div>";
} else {
if ($ConfirmPassword != $Password) {
echo "<div id='Error'>Your password and confirm password does not match.</div>";
} else {
if (strlen($Username) >= 15) {
echo "<div id='Error'>Your username is above fifteen (15) characters!</div>";
} elseif (strlen($Username) < 3) {
echo "<div id='Error'>Your username is under three (3) characters!</div>";
} elseif (!is_alphanumeric($Username)) {
echo "<div id='Error'>Only A-Z and 1-9 is allowed, or there is profanity in your username.</div>";
} else {
$_ENCRYPT = hash('sha512',$Password);
$IP = $_SERVER['REMOTE_ADDR'];
mysqli_query("INSERT INTO Users (Username, Password, Email, IP) VALUES ('$Username', '$_ENCRYPT', '$Email', '$IP')");
$_SESSION['Username']=$Username;
$_SESSION['Password']=$_ENCRYPT;
header("Location: index.php");
}
}
}
}
}
?>