Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $con = mysqli_connect("localhost","root","","vaflichka2");
- // Check connection
- $errno = mysqli_connect_errno();
- if ($errno) {
- echo "Failed to connect to MySQL: " . mysqli_connect_error();
- die();
- }
- /*$query = mysqli_query($con, "SELECT username, email FROM users WHERE id=3");
- while($row = mysqli_fetch_assoc($query)) {
- print_r($row);
- echo "<br>**************************<br>";
- }*/
- if(isset($_POST["username"])) {
- $username = $_POST["username"];
- } else {
- die("Hacking attempt detected. Nice try!");
- }
- if(isset($_POST["password"])) {
- $password = $_POST["password"];
- } else {
- die("Hacking attempt detected. Nice try!");
- }
- if(isset($_POST["confirm_password"])) {
- $confirm_password = $_POST["confirm_password"];
- } else {
- die("Hacking attempt detected. Nice try!");
- }
- if(isset($_POST["email"])) {
- $email = $_POST["email"];
- } else {
- die("Hacking attempt detected. Nice try!");
- }
- if(isset($_POST["name"])) {
- $name = $_POST["name"];
- } else {
- die("Hacking attempt detected. Nice try!");
- }
- $errors = array();
- if(!(strlen($username)>=3 && strlen($username)<=30)) {
- $errors[] = "Error: The username should be between 3 and 30 characters.";
- }
- if(!(strlen($password)>=6 && strlen($password)<=30)) {
- $errors[] = "Error: The password should be between 6 and 30 characters.";
- }
- if($password!=$confirm_password) {
- $errors[] = "Error: The passwords do not match!";
- }
- $query = mysqli_query($con, "SELECT * FROM users WHERE username='".$username."'");
- $userCount = mysqli_num_rows($query);
- if($userCount>0) {
- $errors[] = "Error: The username is already taken!";
- }
- if(count($errors)>0) {
- foreach($errors as $error) {
- echo $error."<br>";
- }
- } else {
- echo "You've registered successfully.";
- $query = mysqli_query($con, "INSERT INTO users (username, password, email, name) VALUES ('".$username."', '".$password."', '".$email."', '".$name."')");
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement