Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if($_SERVER["REQUEST_METHOD"] == "POST"){
- $username = $_POST['username'];
- $password = $_POST['password'];
- $bool = true;
- //open connection to db
- $con = @mysqli_connect('localhost', 'root', '');
- if (!$con){
- echo "Error: " .mysqli_connect_error();
- exit();
- }
- $sql = 'SELECT * FROM users';
- $query = mysqli_query($con, $sql);
- whiile ($row = mysqli_fetch_array($query)){
- $table_users = $row['username'];
- if ($username == $table_users){
- $bool = false;
- Print '<script>alert("username has been taken!");</script>';
- Print '<script>window.location.assign("register.php");</script>';
- }
- }
- if ($bool){
- mysqli_query("INSERT INTO users (username, password) VALUES ('$username','$password')");
- Print '<script>alert("Successfully Registered");</script>';
- Print '<script>window.location.assign("register.php");</script>';
- }
- }
- //Closes connection
- mysqli_close ($con);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement