I’m trying to validate my registration. However data is entered in the database when this part of my code is in comment :
else
if(strlen($password)<7 || strlen($password)>15)
echo "<p>Password must be between 7 and 15 characters!</p>";
else
{
//INSERT function
}
Also none of the if
content is running i only get {"message":"Please fill in all fields."}
as response in my localhost page.
What might the problem be ?
This is my php file :
try{
$res1 = $pdo->prepare("SELECT p_username FROM account_info WHERE p_username LIKE :p_username");
$num_rows1 = $res1->fetchColumn();
$res2 = $pdo->prepare("SELECT a_username FROM account_info WHERE a_username LIKE :a_username");
$num_rows2 = $res2->fetchColumn();
if ($num_rows1==0 && $num_rows2==0)
{
if($p_username && a_username)
{
if($password==$vpassword)
{
if(strlen($p_username)>25||strlen($a_username)>25)
{
echo "<p>Max limit for username are 25 characters</p>";
}
/* else
if(strlen($password)<7 || strlen($password)>15)
echo "<p>Password must be between 7 and 15 characters!</p>";
else
{ */
$sql = "INSERT INTO account_info (a_username,p_username, password, vpassword)
VALUES(:a_username,:p_username, :password, :vpassword)";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':a_username', $a_username, PDO::PARAM_STR);
$stmt->bindParam(':p_username', $p_username, PDO::PARAM_STR);
$stmt->bindParam(':password', $password, PDO::PARAM_STR);
$stmt->bindParam(':vpassword', $vpassword, PDO::PARAM_STR);
$stmt->execute();
echo json_encode(array('message' => 'Congratulations the record was added to the database'));
/* } */
}
else
echo json_encode(array('message' => 'Your passwords do not match!'));
}
else
echo json_encode(array('message' => 'Please fill in all fields.'));
}
else
echo json_encode(array('message' => 'This username already exists, please choose another one.'));
}
// Catch any errors in running the prepared statement
catch(PDOException $e)
{
echo $e->getMessage();
}
?>
Thank you in advance!