I am working on a simple sign up form for my site. Testing it on MAMP. Using ajax to send sign up info to a php file executing this code:
<?php
include("connection.php");
$username = "";
$pw = "";
$errorMsg = "";
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
if ($_POST["submit"] == "Sign Up!")
{
if(!($_POST["username"]))
$errorMsg .= "You must enter a user name. <br />";
else if(strlen($_POST["username"]) < 3 OR strlen($_POST["username"]) > 8)
$errorMsg .= "You user name must be between 3 and 8 characters long.<br />";
else if(!ctype_alnum($_POST["username"]))
$errorMsg .= "Your user name can contain only letters & numbers. <br />";
else
$username = test_input($_POST["username"]);
if(!($_POST["pw"]))
$errorMsg .= "You must enter a password. <br />";
else if(strlen($_POST["pw"]) < 8 OR strlen($_POST["pw"]) > 16)
$errorMsg .= "Your password must be between 8 and 16 characters long.<br />";
else if(!$_POST["confirmpw"])
$errorMsg .= "You must confirm your password.<br />";
else if($_POST["confirmpw"] != $_POST["pw"])
$errorMsg .= "Your password confirmation doesn't match.<br />";
else
$pw = test_input($_POST["pw"]);
if(!$errorMsg)
{
$query = "SELECT * FROM `userinfo` WHERE `username` ='".$username."'";
$result = mysqli_query($connection001, $query);
if (mysqli_num_rows($result) > 0)
$errorMsg = "There is another account registered with this username. Do you want to log in?";
else
{
$query = "INSERT INTO `userinfo` (`username`, `password`) VALUES ('".$username."', '".$pw."')";
mysqli_query($connection001, $query);
}
}
$data = array("username" => $username, "errorMsg" => $errorMsg);
echo json_encode($data);
}
?>
It seems to work cause so far I manage to add entries to my table, but each time I do it I also get this error returned:
TypeError: field_id.match(...) is null
It seems to like it is related to how MAMP manages its database... Is it something I should be concerned about? If so could you kindly point me to a possible solution?