Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include("design/header.php");
- require("connect.php");
- //register code
- if ($_POST['submit'])
- {
- //grab submitted data
- $firstname = $_POST['firstname'];
- $lastname = $_POST['lastname'];
- $username = $_POST['username'];
- $password = $_POST['password'];
- $password_repeat = $_POST['password_repeat'];
- $dob_year = $_POST['dob_year'];
- $dob_month = $_POST['dob_month'];
- $dob_day = $_POST['dob_day'];
- $gender = $_POST['gender'];
- if (
- $firstname&&
- $lastname&&
- $username&&
- $password&&
- $password_repeat&&
- $dob_year&&
- $dob_month&&
- $dob_day&&
- $gender)
- {
- //validate
- if (strlen($firstname)>25 || strlen($lastname)>25 || strlen($username)>25)
- echo "Firstname, lastname and username must be no more than 25 characters.";
- else
- {
- //check password
- if (strlen($password)>25 ||strlen($password)<4)
- echo "Password must be between 4 and 25 characters.";
- else
- {
- //chechk dob
- if (is_numeric($dob_year)&&is_numeric($dob_month)&&is_numeric($dob_day)&&$dob_month)
- {
- if (strlen($dob_year)>4 || strlen($dob_month)>2 || strlen($dob_day)>2)
- echo "Date of birth year must be 4 characters, month and day must be 2 characters";
- else
- {
- if ($gender=="Male"||$gender="female")
- {
- //compare password
- if ($password==$password_repeat)
- {
- if ($dob_month>12||$dob_day>31)
- echo "Date of birth month is bigger than ....";
- else
- {
- // check user
- $query = mysql_query("SELECT * FROM users WHERE username='$username'");
- if (mysql_num_rows($query)>=1)
- echo "That username is allready exist! please choose another username";
- else
- {
- //sucess!! register user....
- $dob_db = "$dob_year-$dob_month-$dob_day";
- $password_db = md5($password);
- switch ($gender)
- {
- case "Male":
- $gender_db = "M";
- break;
- case "Female";
- $gender_db = "F";
- break;
- }
- $register = mysql_query("INSERT INTO users VALUES ('','$firstname','$lastname','$username','$password_db','$dob_db','$gender')");
- echo "Success!";
- }
- }
- }
- else
- echo "Passwords do not match!";
- }
- else
- echo "Gender must be Male or Female!";
- }
- }
- else
- echo "Date of birth must be in number form. For example, 1990/05/29";
- }
- }
- }
- else
- echo "Missing field! Please fill in all fields!";
- }
- else
- echo "Please enter your details and click Register.";
- ?>
- <form action='register.php' method='POST'>
- <p>
- <table width='60%'>
- <tr>
- <td width='40%' align='right'>
- <fotn size='2' face='arial'>Firstname:
- </td>
- <td>
- <input type='text' value='' name='firstname' maxlenght='25'>
- </td>
- </tr>
- <tr>
- <td width='40%' align='right'>
- <fotn size='2' face='arial'>Lastname:
- </td>
- <td>
- <input type='text' value='' name='lastname' maxlenght='25'>
- </td>
- </tr>
- <tr>
- <td width='40%' align='right'>
- <fotn size='2' face='arial'>Username:
- </td>
- <td>
- <input type='text' value='' name='username' maxlenght='25'>
- </td>
- </tr>
- <tr>
- <td width='40%' align='right'>
- <fotn size='2' face='arial'>Password:
- </td>
- <td>
- <input type='password' name='password' maxlenght='25'>
- </td>
- </tr>
- <tr>
- <td width='40%' align='right'>
- <fotn size='2' face='arial'>Repeat password:
- </td>
- <td>
- <input type='password' name='password_repeat' maxlenght='25'>
- </td>
- </tr>
- <tr>
- <td width='40%' align='right'>
- <fotn size='2' face='arial'>Date of birth:
- </td>
- <td>
- <input type='text' name='dob_year' maxlength='4' size='3' value='YYYY'>/<input type='text' name='dob_month' maxlength='2' size='1' value='MM'>/<input type='text' name='dob_day' maxlength='2' size='1' value='DD'>
- </td>
- </tr>
- <tr>
- <td width='40%' align='right'>
- <fotn size='2' face='arial'>Gender:
- </td>
- <td>
- <select name='gender'>
- <option>Female</option>
- <option>Male</option>
- </select>
- </td>
- </tr>
- </table>
- <div align='right'><input type=submit name='submit' value='Register'> </div>
- </form>
- <?php
- include("design/footer.php");
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement