Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- {
- include("config.php");
- $error = "";
- $username = "";
- $msgGame = "";
- if($_SERVER["REQUEST_METHOD"] == "POST" AND isset($_POST['back'])) {
- header("location: login.php");
- }
- else if($_SERVER["REQUEST_METHOD"] == "POST") {
- // username and password sent from form
- $username = mysqli_real_escape_string($db,$_POST['username']);
- $pass1 = mysqli_real_escape_string($db,$_POST['password1']);
- $pass2 = mysqli_real_escape_string($db,$_POST['password2']);
- //searches for username that is aptemting to register
- $sql = "SELECT id FROM users WHERE username = '$username'";
- $result = mysqli_query($db,$sql);
- $count = mysqli_num_rows($result);
- // If no username not found in database then proceed
- if($count == 0) {
- // Checks if password matches and is at least 6 letters/symbols long
- if ($pass1 == $pass2 AND strlen($pass1) > 5){
- //encrypts password (twice)
- $pass = md5(md5($pass1));
- $sql = "INSERT INTO users (username, password) VALUES ('$username', '$pass')";
- $result = mysqli_query($db,$sql);
- // if registration successful then continue to next page
- if ($result){
- if (isset($_POST['game'])){
- $msgGame = "SUCCESS";
- }
- else{
- header("location: registration_success.php");
- }
- }else{
- $msgGame = "FAIL";
- $error = "Could not add user...";
- }
- }else{
- $msgGame = "FAIL";
- $error = "Password not matching or too short (min 6 symbols)!! Please try again.";
- }
- }else {
- $msgGame = "FAIL";
- $error = "Username <u>". $username."</u> already exists, sorry!";
- }
- // checks is game variable is set
- if (isset($_POST['game'])){
- // displays msg and and returns
- echo $msgGame;
- return; // (return aka don't run rest of the code)
- }
- }
- } catch(exception $ex){ echo $ex; }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement