Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- </head>
- <body>
- <h2>Welcome to MyPeople</h2>
- <p style="text-align: right;">USERNAME                      PASSWORD                                    <br>
- <input type="text" name="reg_username">
- <input type="password" name="reg_password">
- <input type="submit" name="submit" value="Log In"><br>
- </p>
- <?php
- //checking if mandatory fields are empty and if valid data is entered
- // define variables and set to empty values
- $nameErr = $emailErr = $genderErr = $usernameErr = $passwordErr = "";
- $name = $email = $gender = $username = $password = "";
- if ($_SERVER["REQUEST_METHOD"] == "POST") {
- if (empty($_POST["name"])) {
- $nameErr = "Name is required";
- } else {
- $name = test_input($_POST["name"]);
- // check if name only contains letters and whitespace
- if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
- $nameErr = "Only letters and white space allowed";
- }
- }
- if (empty($_POST["email"])) {
- $emailErr = "Email is required";
- } else {
- $email = test_input($_POST["email"]);
- // check if e-mail address is well-formed
- if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
- $emailErr = "Invalid email format";
- }
- }
- if (empty($_POST["username"])) {
- $usernameErr = "Username is required";
- } else {
- $username = trim($username);
- $username = htmlspecialchars($username);
- }
- if (empty($_POST["password"])) {
- $passwordErr = "Password is required";
- }
- if (empty($_POST["gender"])) {
- $genderErr = "Gender is required";
- } else {
- $gender = test_input($_POST["gender"]);
- }
- }
- function test_input($data) {
- $data = trim($data);
- $data = stripslashes($data);
- $data = htmlspecialchars($data);
- return $data;
- }
- ?>
- <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
- <p><b> New User? Register now!</b><br><br>
- Name: <input type="text" name="fname" value="<?php echo $name;?>"><span> *<?php echo $nameErr;?></span><br><br>
- Email ID: <input type="text" name="email" value="<?php echo $email;?>"><span> *<?php echo $emailErr;?></span><br><br>
- Phone no: <input type="number" name="phnumber"><br><br>
- Date of Birth: <input type="date" name="dob"><br><br>
- Username: <input type="text" name="username" value="<?php echo $username;?>"><span> *<?php echo $usernameErr;?></span><br><br>
- New Password: <input type="password" name="password" value="<?php echo $password;?>"><span> *<?php echo $passwordErr;?></span><br><br>
- Gender: <input type="radio" name="gender" value="female" <?php if (isset($gender) && $gender=="female") echo "checked";?>>Female <input type="radio" name="gender" value="male" <?php if (isset($gender) && $gender=="male") echo "checked";?>> Male <span> *<?php echo $genderErr;?></span><br><br>
- <input type="submit" name="register" value="Register"><br>
- <p>* marked fields are mandatory</p>
- </form>
- </body>
- </html>
Add Comment
Please, Sign In to add comment