How to prevent duplicate Usernames in php/mysql

后端 未结 4 1508
滥情空心
滥情空心 2021-01-17 04:47

(This is my first try with php)

I have a very basic register page. http://graves-incorporated.com/test_sites/member_test/register/register.php

* I j

4条回答
  •  迷失自我
    2021-01-17 05:50

    Please fill out all fields.';
    
        }elseif($_POST['password'] != $_POST['conf_pass']){
            echo 'Your Passwords do not match.';
        }else{
    
            $dup = mysql_query("SELECT username FROM users WHERE username='".$_POST['username']."'");
            if(mysql_num_rows($dup) >0){
                echo 'username Already Used.';
            }
            else{
                $url = 'http://graves-incorporated.com/test_sites/plantation_park_2012/';
                echo '';
    
                $sql = mysql_query("INSERT INTO users VALUES(NULL, '$_POST[username]', '$_POST[password]', '$_POST[email]')");     
                if($sql){
                     echo 'Congrats, You are now Registered.';
                }
                else{
                    echo 'Error Registeration.';
                }
            }
        }
    }
    ?>
    

提交回复
热议问题