Can somebody help me? I am starting to learn PHP and i am trying to validate my username and password. it should only input characters, otherwise it will prompt validation error. However, even if i entered numbers, my form is still successful. I've used is_string function to validate but it seems it's not working.
Here's my code:
<?php
if(isset($_POST['submit'])) {
$username = $_POST['username'];
$password = $_POST['password'];
if(!is_string($username) && !is_string($password)) {
echo "Error! Please input characters only.";
}
else {
echo "successful";
}
}
else {
$username = "";
echo "Please log in.";
}
?>
<!DOCTYPE html>
<html>
<head>
<title> First Page </title>
<meta charset="UTF-8"/>
</head>
<body>
<form action="basic.php" method="POST">
Username: <input type="text" name="username" value="<?php $username ?>" /> <br/>
Password: <input type="password" name="password" /> <br/>
Submit: <input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
||instead of&&.||instead of&&to validate the input