Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $reg = @$_POST['reg'];
- //declaring variables to prevent errors
- $fn = ""; //First Name
- $ln = ""; //Last Name
- $un = ""; //Username
- $em = ""; //Email
- $em2 = ""; //Email 2
- $pswd = ""; //Password
- $pswd2 = ""; // Password 2
- $d = ""; // Sign up Date
- $u_check = ""; // Check if username exists
- //registration form
- $fn = strip_tags(@$_POST['fname']);
- $ln = strip_tags(@$_POST['lname']);
- $un = strip_tags(@$_POST['uname']);
- $em = strip_tags(@$_POST['email']);
- $em2 = strip_tags(@$_POST['email2']);
- $pswd = strip_tags(@$_POST['password']);
- $pswd2 = strip_tags(@$_POST['password2']);
- $d = date("Y-m-d"); // Year - Month - Day
- if ($reg) {
- if ($em==$em2) {
- // Check if user already exists
- //create a database connection here :
- $servername = "localhost";
- $username = "username";
- $password = "password";
- $dbname = "giveyourdatabasenamehere";
- // Create new database connection
- $conn = mysqli_connect($servername, $username, $password, $dbname);
- // Check connection
- $sql = "SELECT username FROM users WHERE username='$un'";
- $u_check = mysqli_query($conn, $sql);
- // Count the amount of rows where username = $un
- $check = mysqli_num_rows($u_check);
- //Check whether Email already exists in the database
- $query2="SELECT email FROM users WHERE email='$em'";
- $e_check = mysqli_query($con,$query2);
- //Count the number of rows returned
- $email_check = mysqli_num_rows($e_check);
- if ($check == 0) {
- if ($email_check == 0) {
- //check all of the fields have been filed in
- if ($fn&&$ln&&$un&&$em&&$em2&&$pswd&&$pswd2) {
- // check that passwords match
- if ($pswd==$pswd2) {
- // check the maximum length of username/first name/last name does not exceed 25 characters
- if (strlen($un)>25||strlen($fn)>25||strlen($ln)>25) {
- echo "The maximum limit for username/first name/last name is 25 characters!";
- }
- else
- {
- // check the maximum length of password does not exceed 25 characters and is not less than 5 characters
- if (strlen($pswd)>30||strlen($pswd)<5) {
- echo "Your password must be between 5 and 30 characters long!";
- }
- else
- {
- //encrypt password and password 2 using md5 before sending to database
- $pswd = md5($pswd);
- $pswd2 = md5($pswd2);
- $query = mysqli_query($conn,"INSERT INTO users VALUES ('','$un','$fn','$ln','$em','$pswd','$d','0','Write something about yourself.','','','no')");
- die("<h2>Welcome to the HoogleyBoogley Network</h2>Login to your account to get started ...");
- }
- }
- }
- else {
- echo "Your passwords don't match!";
- }
- }
- else
- {
- echo "Please fill in all of the fields";
- }
- }
- else
- {
- echo "Sorry, but it looks like someone has already used that email!";
- }
- }
- else
- {
- echo "Username already taken ...";
- }
- }
- else {
- echo "Your E-mails don't match!";
- }
- }
- ?>
Add Comment
Please, Sign In to add comment