Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if($_SERVER["REQUEST_METHOD"] == "POST"){
- $username = mysql_real_escape_string($_POST['username']);
- $password = mysql_real_escape_string($_POST['password']);
- $email = mysql_real_escape_string($_POST['email']);
- $fname = mysql_real_escape_string($_POST['fname']);
- $lname = mysql_real_escape_string($_POST['lname']);
- $bool = true;
- mysql_connect("localhost", "root","rot_darshan") or die("Cannot connect to server"); //Connect to server
- mysql_select_db("first_db") or die("Cannot connect to database"); //Connect to database
- $query = mysql_query("Select * from users"); //Query the users table
- while($row = mysql_fetch_array($query)) //display all rows from query
- {
- $table_users = $row['username']; // the first username row is passed on to $table_users, and so on until the query is finished
- if($username == $table_users) // checks if there are any matching fields
- {
- $bool = false; // sets bool to false
- Print '<script>alert("Username has been taken!");</script>'; //Prompts the user
- Print '<script>window.location.assign("register.php");</script>'; // redirects to register.php
- }
- }
- if($bool) // checks if bool is true
- {
- mysql_query("INSERT INTO users (username, password,fname,lname,email) VALUES ('$username','$password','$fname','$lname','$email')"); //Inserts the value to table users
- Print '<script>alert("Successfully Registered!");</script>'; // Prompts the user
- Print '<script>window.location.assign("register.php");</script>'; // redirects to register.php
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement