Tutorial Title: Validating The Form Values
Course: PHP
Instructor: Muhammad Samim
1. Understanding of Different Validation
<?php
if(isset($_POST["click"])){
$anyNameOfVariableForUserName = $_POST["anyNameForEmail"];
$anyNameOfVariableForPassword = $_POST["anyNameForPassword"];
$validEmail = array("Muhammad","Samim","Akhtar","Akbar"); //Array of valid names
$minimum = 3;
$maximum = 15;
if (strlen($anyNameOfVariableForUserName) < $minimum) //strlen will check the length of the string
{
echo "Email Error: Minimum characters are 5";
}
elseif (strlen($anyNameOfVariableForUserName) > $maximum) //strlen will check the length of the string
{
echo "<br>Email Error: Maximum characters are 12";
}
else {
echo "You are logged in successfully";
}
if (strlen($anyNameOfVariableForPassword) < $minimum) //strlen will check the length of the string
{
echo "<br>Password Error: Password length must be more than 6 characters!";
}
elseif(strlen($anyNameOfVariableForPassword) > $maximum) //strlen will check the length of the string
{
echo "<br>Password Error: Password lenghth must be less than 12 characters!";
}
if(in_array($anyNameOfVariableForUserName, $validEmail)) //Checking name if a name is entered is already available is array
{
echo "<br>Valid User Enterd!";
}
else{
echo "<br>Invalid User!";;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<form action="22validatingFormValue.php" method="post">
<br><input type="text" placeholder="Email" name="anyNameForEmail">
<br><input type="password" placeholder="Password" name="anyNameForPassword">
<br><input type="submit" name="click">
</form>
</body>
</html>
Course: PHP
Instructor: Muhammad Samim
1. Understanding of Different Validation
<?php
if(isset($_POST["click"])){
$anyNameOfVariableForUserName = $_POST["anyNameForEmail"];
$anyNameOfVariableForPassword = $_POST["anyNameForPassword"];
$validEmail = array("Muhammad","Samim","Akhtar","Akbar"); //Array of valid names
$minimum = 3;
$maximum = 15;
if (strlen($anyNameOfVariableForUserName) < $minimum) //strlen will check the length of the string
{
echo "Email Error: Minimum characters are 5";
}
elseif (strlen($anyNameOfVariableForUserName) > $maximum) //strlen will check the length of the string
{
echo "<br>Email Error: Maximum characters are 12";
}
else {
echo "You are logged in successfully";
}
if (strlen($anyNameOfVariableForPassword) < $minimum) //strlen will check the length of the string
{
echo "<br>Password Error: Password length must be more than 6 characters!";
}
elseif(strlen($anyNameOfVariableForPassword) > $maximum) //strlen will check the length of the string
{
echo "<br>Password Error: Password lenghth must be less than 12 characters!";
}
if(in_array($anyNameOfVariableForUserName, $validEmail)) //Checking name if a name is entered is already available is array
{
echo "<br>Valid User Enterd!";
}
else{
echo "<br>Invalid User!";;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<form action="22validatingFormValue.php" method="post">
<br><input type="text" placeholder="Email" name="anyNameForEmail">
<br><input type="password" placeholder="Password" name="anyNameForPassword">
<br><input type="submit" name="click">
</form>
</body>
</html>
Comments
Post a Comment