Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!-- how to make members when login "keep me signed in" and how to make users 13+ with the date input -->
- <?php
- if(!empty($_POST["register-user"])) {
- /* Form Required Field Validation */
- foreach($_POST as $key=>$value) {
- if(empty($_POST[$key])) {
- $error_message = "All Fields are required";
- break;
- }
- }
- /* Password Matching Validation */
- if($_POST['password'] != $_POST['confirm_password']){
- $error_message = 'Passwords should be same<br>';
- }
- /* Email Validation */
- if(!isset($error_message)) {
- if (!filter_var($_POST["userEmail"], FILTER_VALIDATE_EMAIL)) {
- $error_message = "Invalid Email Address";
- }
- }
- $userName = "userName";
- $usernamelenght = strlen($userName);
- if($usernamelenght <= 25)
- {}
- else
- {
- $error_message = "Your username cannot exceed 25 characters";
- }
- $email = "email";
- $emaillenght = strlen($email);
- if($emaillenght <= 50)
- {}
- else
- {
- $error_message = "Your email cannot exceed 50 characters";
- }
- /* Validation to check if gender is selected */
- if(!isset($error_message)) {
- if(!isset($_POST["gender"])) {
- $error_message = " All Fields are required";
- }
- }
- /* Validation to check if Terms and Conditions are accepted */
- if(!isset($error_message)) {
- if(!isset($_POST["terms"])) {
- $error_message = "Accept Terms and Conditions to Register";
- }
- }
- if(!isset($error_message)) {
- require_once("dbcontroller.php");
- $db_handle = new DBController();
- $query = "INSERT INTO members (username, firstname, lastname, password, email, gender, dob) VALUES
- ('" . $_POST["userName"] . "', '" . $_POST["firstName"] . "', '" . $_POST["lastName"] . "', '" . md5($_POST["password"]) . "', '" . $_POST["userEmail"] . "', '" . $_POST["gender"] . "' , '" . $_POST["dob"] . "' )";
- $result = $db_handle->insertQuery($query);
- if(!empty($result)) {
- $error_message = "";
- $success_message = "You have registered successfully!";
- unset($_POST);
- } else {
- $error_message = "Problem in registration. Try Again!";
- }
- }
- }
- ?>
- <html>
- <?php
- include 'C:wamp64wwwEtegostylesignup.css';
- ?>
- <script type="text/javascript">
- var minAge = 13;
- function _calcAge() {
- var dob = new Dob(document.getElementById("dob").value);
- var today = new dob();
- var timeDiff = Math.abs(today.getTime() - dob.getTime());
- var age1 = Math.ceil(timeDiff / (1000 * 3600 * 24)) / 365;
- return age1;
- }
- //Compares calculated age with minimum age and acts according to rules//
- function _setAge() {
- var age = _calcAge();
- //alert("my age is " + age);
- if (age < minAge) {
- var jsdemo = "$error_message = "You must be 13 and over";
- } else
- var jsdemo = "$error_message = "correct";
- }
- </script>
- <head>
- <script src='https://www.google.com/recaptcha/api.js'></script>
- <title>https://Etego/signup.com</title>
- </head>
- <body class="bg">
- <form name="frmRegistration" method="post" action="">
- <table border="0" width="500" align="center" class="demo-table">
- <?php if(!empty($success_message)) { ?>
- <div class="success-message"><?php if(isset($success_message)) echo $success_message; ?></div>
- <?php } ?>
- <?php if(!empty($error_message)) { ?>
- <div class="error-message"><?php if(isset($error_message)) echo $error_message; ?></div>
- <?php } ?>
- <tr>
- <td>User Name</td>
- <td><input type="text" class="demoInputBox allinsc" name="userName" value="<?php if(isset($_POST['userName'])) echo $_POST['userName']; ?>"></td>
- </tr>
- <tr>
- <td>First Name</td>
- <td><input type="text" class="demoInputBox allinsc" name="firstName" value="<?php if(isset($_POST['firstName'])) echo $_POST['firstName']; ?>"></td>
- </tr>
- <tr>
- <td>Last Name</td>
- <td><input type="text" class="demoInputBox allinsc" name="lastName" value="<?php if(isset($_POST['lastName'])) echo $_POST['lastName']; ?>"></td>
- </tr>
- <tr>
- <td>Password</td>
- <td><input type="password" class="demoInputBox allinsc" name="password" value=""></td>
- </tr>
- <tr>
- <td>Confirm Password</td>
- <td><input type="password" class="demoInputBox allinsc" name="confirm_password" value=""></td>
- </tr>
- <tr>
- <td>Email</td>
- <td><input type="text" class="demoInputBox allinsc" name="userEmail" value="<?php if(isset($_POST['userEmail'])) echo $_POST['userEmail']; ?>"></td>
- </tr>
- <tr>
- <td>Date Of birth</td>
- <td><input type="date" id="dob" value="<?php print(date("YYYY-MM-DD"))?>" class="demoInputBox" name="dob" value="<?php if(isset($_POST['dob'])) echo $_POST['dob']; ?>"></td>
- </tr>
- <tr>
- <td>Gender</td>
- <td><input type="radio" name="gender" value="Male" <?php if(isset($_POST['gender']) && $_POST['gender']=="Male") { ?>checked<?php } ?>> Male
- <input type="radio" name="gender" value="Female" <?php if(isset($_POST['gender']) && $_POST['gender']=="Female") { ?>checked<?php } ?>> Female
- <input type="radio" name="gender" value="not specified" <?php if(isset($_POST['gender']) && $_POST['gender']=="not specified") { ?>checked<?php } ?>> not specified
- </td>
- </tr>
- <tr>
- <td colspan=2>
- <input type="checkbox" name="terms"> I accept <a href="terms.html">Terms and Conditions</a>
- <input type="submit" name="register-user" value="Register" class="btnregister"></td>
- </tr>
- </table>
- </form>
- <div class="bg9"></div>
- <div class="header1"></div>
- <div class="hdetail1"></div>
- <div class="header2"></div>
- <div class="hdetail2"></div>
- <a href="index2.php">
- <ul>
- <li class="etegotxt1">
- <span>Etego</span>
- </li>
- </ul>
- <img src="EtegoLogo2.png" alt="Etego logo" width="50" height="50" class="logo1">
- </a>
- <ul class="ul1">
- <li class="li1"><a class="a1 h1" href="index2.php">Home</a></li>
- <li class="li1"><a class="a1 n1" href="news.html">News</a></li>
- <li class="li1"><a class="a1 c1" href="contact.html">Contact</a></li>
- <li class="li1"><a class="a1 aa1" href="about.html">About</a></li>
- </ul>
- <table class="login1">
- <tr>
- </tr>
- <tr >
- <td><input type="text" class="inputtext" placeholder="Email or Username">
- </td>
- <td><input type="password" class="inputtext" placeholder="Password">
- </td>
- <td>
- <div id="button" class="log1">Log In</div>
- </td>
- </tr>
- <tr>
- <td>
- <div class="row2" class="rowh"><input type="checkbox" checked>Keep me logged in</div>
- </td>
- <td class="row2 h"><a class="fyp1" href="Contact.html">Forgot your password?</a></td>
- </table>
- <section>
- <img src="EtegoLogo2.png" alt="Etego logo" width="200" height="200" class="logo2">
- <h1 class="text2"
- data-sitekey="6LdoU28UAAAAALkl4SMrM91_mJRWAXEtb5YYlYof"
- data-callback="YourOnSubmitFn" onclick="_setAge()">
- Sign Up
- </h1>
- <h1 class="text1">
- What is Etego?
- </h1>
- <p class="p1">
- Etego is a free social network made for <br /> people who just wants to spend more <br /> time with friends and family. Etego's only goal is to make you happy. you might be a co-worker trying to make an ad for hiring workers, or you might also be a teen trying to make some money by walking your neighbor hood dogs. But after all, <br /> Etego is there to stay and will always be free.
- </p>
- </section>
- <div class="clear-both"></div>
- <p class="cr1"><a href="terms.html" class="tos2">Terms Of Services</a> • <a href="aboutme.html" class="tos2">About the author</a><br />Copyright © 2018-2019 Charles Chevrier All Rights Reserved <br />By clicking register you accept the <a href="terms.html" class="tos2">terms of services</a> and that you have read the <a href="terms.html"class="tos2">privacy policy</a></p>
- <div class="bothead"></div>
- <div class="botd"></div>
- <div class="table1"></div>
- </body></html>
- <?php
- class DBController {
- public $host = "localhost";
- public $user = "root";
- public $password = "";
- public $database = "members";
- public $conn;
- function __construct() {
- $this->conn = $this->connectDB();
- }
- function connectDB() {
- $this->conn = mysqli_connect($this->host,$this->user,$this->password,$this->database);
- return $this->conn;
- }
- function runQuery($query) {
- $result = mysqli_query($this->conn,$query);
- while($row=mysqli_fetch_assoc($result)) {
- $resultset[] = $row;
- }
- if(!empty($resultset))
- return $resultset;
- }
- function numRows($query) {
- $result = mysqli_query($this->conn,$query);
- $rowcount = mysqli_num_rows($result);
- return $rowcount;
- }
- function updateQuery($query) {
- $result = mysqli_query($this->conn,$query);
- if (!$result) {
- die('Invalid query1: ' . mysqli_error($this->conn));
- } else {
- return $result;
- }
- }
- function insertQuery($query) {
- $result = mysqli_query($this->conn,$query);
- if (!$result) {
- die('Invalid query2: ' . mysqli_error($this->conn));
- } else {
- return $result;
- }
- }
- function deleteQuery($query) {
- $result = mysqli_query($this->conn,$query);
- if (!$result) {
- die('Invalid query3: ' . mysqli_error($this->conn));
- } else {
- return $result;
- }
- }
- }
- /* Email already exists */
- /*line 63*/
- $db = new DBController;
- $stmt = $db->conn->prepare("SELECT * FROM members WHERE email = ?");
- $stmt->bind_param("s", $email);
- $stmt->execute();
- $result = $stmt->get_result();
- if($result->num_rows > 0) {
- $error_message = "Email already exists";
- }
- //end of email existance
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement