Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (isset($_POST['register'])) {
- if (empty($_POST['username']) || empty($_POST['password']) || empty($_POST['repassword'])) {
- $error = "Please fill in all the information";
- }
- else {
- $query = mysql_query("SELECT username FROM login WHERE username='$username'");
- $num = mysql_num_rows($query);
- if ($num > 0) {
- $error = "Username already taken";
- }
- else {
- // Define $username and $password
- $username=$_POST['username'];
- $password=$_POST['password'];
- $repassword=$_POST['repassword'];
- // Create connection
- $conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- // Checking Username Length
- if (strlen($username) < 4) {
- $error = "Short username are easy to guess. Try one with at least 4 characters.";
- }
- // Checking Password Length
- elseif (strlen($password) < 6) {
- $error = "Short passwords are easy to guess. Try one with at least 12 characters.";
- }
- else {
- // Checking Re-enter Password
- if ($password != $repassword) {
- $error = "These passwords don't match. Try again?";
- }
- else {
- // Encryption Password
- $enpassword = md5($password);
- $sql = "INSERT INTO login (username, password) VALUES ('$username', '$enpassword')";
- if ($conn->query($sql) === TRUE) {
- header("location: index.php");
- }
- else {
- echo "Error: " . $sql . "<br>" . $conn->error;
- }
- $conn->close();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement