//Login info står herover, men er af sikkerhedsmæssige årsager ikke med. /** other variables */ $userNameIsUnique = true; $passwordIsValid = true; $userIsEmpty = false; $passwordIsEmpty = false; $password2IsEmpty = false; if ($_SERVER["REQUEST_METHOD"] == "POST") { //Checking whether the user has filled in the wishers name in the text field if ($_POST["user"]=="") $userIsEmpty = true; } // SQL Connect $db_connect = mysql_connect($db_hostname, $db_username, $db_password); $db_select = mysql_select_db($db_database, $db_connect); mysql_set_charset('utf8', $db_connect); // Sætter charset til utf8 når det bliver trukket ud //Testing SQL connection if(!$db_connect) { die("Fejlfri:" . mysql_errno()); } elseif(!$db_select) { die("Fejl:" . mysql_errno()); } //Checking if the name is already in use $user = mysql_real_escape_string($_POST["user"]); $query = mysql_query("SELECT id FROM Wishlist WHERE user='$user'"); $wisherIDnum = mysql_num_rows($query); if ($wisherIDnum) { $userNameIsUnique = false; } //Tests if the passwords are alike and is filled. if ($_POST["password"]=="") $passwordIsEmpty = true; if ($_POST["password2"]=="") $password2IsEmpty = true; if ($_POST["password"]!=$_POST["password2"]) { $passwordIsValid = false;} //Checks whether all the boolean values are correct. if (!$userIsEmpty && $userNameIsUnique && !$passwordIsEmpty && !$password2IsEmpty && $passwordIsValid) { $password = mysql_real_escape_string($_POST['password']); $encrypt = md5($password); mysql_query("INSERT Wishlist (user, password) VALUES (' " . $user . " ', '" . $encrypt. "')"); mysql_free_result($query); mysql_close; echo "Congratulations, you have now been added!"; exit; } ?> Welcome!
Your name:
"); } if (!$userNameIsUnique) { echo ("The person already exists. Please check the spelling and try again"); echo ("
"); } ?> Password:
"); } ?> Please confirm your password:
"); } if (!$password2IsEmpty && !$passwordIsValid) { echo ("The passwords do not match!"); echo ("
"); } ?>