Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $con = mysql_connect("localhost","root","");
- if (!$con)
- {
- die('Could not connect: ' . mysql_error());
- }
- mysql_select_db("users", $con) or die("Can't select db.");
- $username = $_POST['username']; // or $_POST["username"]; Doesn't matter if " or ' here
- $password = $_POST['password'];
- $error = false;
- if($_POST){
- if(empty($username){ //$username is exactly the same as $_POST['username']
- echo "Empty username!";
- $error = true;
- }
- if(empty($password)){
- echo "Empty password";
- $error = true;
- }
- if($error != true){ //Or if($error == false){ - it's the same
- $usercheck = mysql_query("SELECT * FROM users WHERE username='$username' LIMIT 1");
- if(mysql_num_rows($usercheck) == 0){
- mysql_query("INSERT INTO users (username, password)
- VALUES ('$username', '$password')") or die(mysql_error());
- echo "Registration Succesful";
- } else {
- echo "Username {$username} is already taken.";
- }
- }
- }
- mysql_close($con);
- ?>
- <!DOCTYPE html>
- <html>
- <body>
- <form action="register.php" method="POST">
- Username: <input type="text" name="username"><br>
- Password: <input type="password" name="password"><br />
- <input type="submit" value="Login."></form> <br />
- </body>
- </html>
Add Comment
Please, Sign In to add comment