PHP: 1. C reate a HTML form, accept the input: Username, Password, Email & Phone
ID: 3791587 • Letter: P
Question
PHP:
1. Create a HTML form, accept the input: Username, Password, Email & Phone number. Post the data to a PHP script. Validate each information using PHP, and produce the result.
Validation criteria:
Username:
Must be 5 - 20 characters
Must contain alphabets.
May contain numbers or
underscore.
Password:
May contain letter and numbers
Must contain at least 1 number and 1 letter
May contain any of these characters: !@#$%
Must be 8-12 characters
Required Output(1):
Required Output (2):
Username:
Must be 5 - 20 characters
Must contain alphabets.
May contain numbers or
underscore.
Password:
May contain letter and numbers
Must contain at least 1 number and 1 letter
May contain any of these characters: !@#$%
Must be 8-12 characters
Sign up C fi ocalhost 8080/2016/signup.html Sign up Username: James Tay92 Password Email ID: james 92@live.com Ph. Number: 123-678-4444 Clear SendExplanation / Answer
The HTML form is as under..
<html>
<head>Form Validation</head>
<body>
<p> Enter Username </p>
<FORM action="d://signup.php" method="post"> // posting this form to .php file for validation on submit
<P>
<LABEL for="firstname">Username </LABEL>
<INPUT type="text" id="Username"><BR>
<LABEL for="lastname">Password </LABEL>
<INPUT type="text" id="Password"><BR>
<LABEL for="Email">Email </LABEL>
<INPUT type="text" id="Email"><BR>
<LABEL for="PhoneNo">PhoneNo </LABEL>
<INPUT type="text" id="PhoneNo"><BR>
<INPUT type="submit" value="Send"> <INPUT type="reset">
</P>
</FORM>
</html>
__________________________________________________________
PhP program for Validation
<?php
$con = mysql_connect("localhost","root",""); // connecting to the local host server and www root folder
mysql_select_db("validate",$con); //Selecting the database as validate
$username=$_POST['user']; //post because you don't want the show the data to the public
$password=$_POST['pass'];
$phoneno=$_POST['phno'];
$email=$_POST['email'];
$result = mysql_query("SELECT * FROM user");// retreieving data from user table
while($row=mysql_fetch_array($result))
{
$user=$row['USER_NAME'];
$pass=$row['PASS_WORD'];
$Email=$row['EMAIL_ID'];
$PhNo=$row['Phone_No'];
}
$num=mysql_num_rows($result);echo $num;
for($i=1;$i<=$num; $i++){
if($username == $user && $password==$pass)
{
header("Location: signup.php");
}
else if($password != $pass ||$username != $user )
{
echo("Please Enter Correct Username and Password ...");
header("Location: validate.php");
}
if(preg_match("/^[0-9]{3}-[0-9]{4}-[0-9]{4}$/", $Phone_No)) {
// $Phone_No is valid }
$Emaill = test_input($_POST["Email"]);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format";
}
}
?>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.