Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- echo "<h1>Register</h1>";
- $submit = $_POST['submit'];
- //form data
- $fullname = strip_tags($_POST['fullname']);
- $username = strip_tags($_POST['username']);
- $password = strip_tags($_POST['password']);
- $repeatpassword = strip_tags($_POST['repeatpassword']);
- $date = date("Y-m-d");
- $email = strip_tags($_POST['email']);
- $dob_year = strip_tags($_POST['dob_year']);
- $dob_month = strip_tags($_POST['dob_month']);
- $dob_day = strip_tags($_POST['dob_day']);
- $gender = strip_tags($_POST['gender']);
- //check for existance
- echo $submit,$fullname,$username,$password,$repeatpassword,$email,$dob_year,$dob_day,$dob_day,$gender;
- if($submit&&$fullname&&$username&&$password&&$repeatpassword&&$email&&$dob_year&&$dob_day&&$dob_day&&$gender)
- {
- //$email=$_POST['email'];
- if ($password==$repeatpassword)
- {
- //check char length of username and fullname
- if (strlen($username)>25||strlen($fullname)>25)
- {
- echo "Length of username or fullname is too long!";
- }
- else
- {
- //check password length
- if (strlen($password)>25||strlen($password)<6)
- {
- echo "Password must be between 6 and 25 characters";
- }
- else
- {
- if ( ctype_digit($dob_year) && ctype_digit($dob_month) && ctype_digit($dob_day) )
- {
- echo "Year, month and day of birth must be numeric values.";
- unset($dob_year);
- unset($dob_month);
- unset($dob_day);
- }
- else
- {
- if ( strlen($dob_year) > 4 || strlen($dob_year) > 2 || strlen($dob_year) > 2 )
- echo "Year of birth must be 4 characters long, month and day must be 2.";
- unset($dob_year);
- unset($dob_month);
- unset($dob_day);
- }
- //check dob limits for month and day
- if ($dob_month>12||$dob_day>31)
- {
- echo "Date of birth month or day is higher than expected!";
- unset($dob_year);
- unset($dob_month);
- unset($dob_day);
- }
- //check for existing user
- $query = mysql_query("SELECT * FROM users WHERE username='" . mysql_real_escape_string($username) . "' LIMIT 1");
- if (mysql_num_rows($query) > 0)
- {
- echo "That username is already taken.";
- }
- // enorypt password
- $password = md5($password);
- $repeatpassword = md5($repeatpassword = md5($repeatpassword));
- //check email
- if (!ereg("[A-Z0-9._%-]+@[A-Z0-9.-]{2}([A-Z0-9.-])?\.[A-Z]{2,4}",$email)){
- echo "Enter a valid E-mail Address";
- }
- else{
- //open database
- $connect = mysql_connect("localhost","root","");
- mysql_select_db("phplogin"); //select database
- $queryreg = mysql_query("
- INSERT INTO users (`id`, `fullname`, `username`, `password`, `date`,`email`,`dob_year`,`dob_day`,`dob_day`,`gender`) VALUES (NULL, '$fullname', '$username', '$password', '$date','$email','$dob','$dob_year','$dob_day','$dob_day','$gender');
- ");
- if (!$queryreg)
- {
- die('Register Failed'.mysql_error());
- }
- echo "You have been registered! <a href='index.php'> Return to login page</a>";
- //close mail check
- }
- }
- }
- }
- else
- {
- echo "Your password do not match!";
- }
- }
- else
- {
- echo "Please fill in <b>all<b> fields!";
- }
- ?>
- <html>
- <p>
- <form action='register.php' method='POST'>
- <table>
- <tr>
- <td>
- Your full name:
- </td>
- <td>
- <input type='text' name='fullname' value='<?php echo $fullname; ?>'
- </td>
- <tr>
- <td>
- Choose a username:
- </td>
- <td>
- <input type='text' name='username' value='<?php echo $username; ?>'
- </td>
- <tr>
- <td>
- Choose a password:
- </td>
- <td>
- <input type='password' name='password'>
- </td>
- <tr>
- <td>
- Repeat your password:
- </td>
- <td>
- <input type='password' name='repeatpassword'>
- </td>
- </tr>
- <tr>
- <td>
- Type Your Email:
- </td>
- <td>
- <input type='text' name='email' value='<?php echo $email; ?>'
- </td>
- <tr>
- <td>
- Date of birth:
- </td>
- <td>
- <input type='text' name='dob_year' maxlength='4' size='3' value='<?php if ($dob_year) echo $dob_year; else echo "YYYY";?>'> /<input type='text' name='dob_month' maxlength='2' size='1' value='<?php if ($dob_month) echo $dob_month; else echo "MM";?>'> / <input type='text' name='dob_day' maxlength='2' size='1' value='<?php if ($dob_day) echo $dob_day; else echo "DD";?>'>
- </td>
- </tr>
- <tr>
- <td>
- Gender:
- </td>
- <td>
- <select name='gender'>
- <option value="F">Female</option>
- <option value="M">Male</option>
- </select>
- </td>
- </tr>
- </table>
- <p>
- <input type='submit' name='submit' value='Register'>
- </form>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement