Data not going into mySQL db

Hi, I’m having real issues with my user registration page. Nothing is being input into the database but I’m not getting any error messages. It seems that my code isn’t connecting to the database. I’ve tried a few things i’ve found on here and none seem to be working.

  if ($response != null && $response->success) {
    echo "Hi " . $_POST['username'] . " thanks for registering!";
	if (isset($_SESSION['logged'])){
		$s_username = $_SESSION['username'];
		echo $message = "You are already logged in as $s_username.
		Please logout before trying to register.";

	}else{
		if ($submit=="Register") {
			if ($username&&$password&&$repeatpassword){
				if ($password==$repeatpassword){
					if (strlen($username)>25) {
				 		echo $message = "Username is too long";
					}else{
						if (strlen($password)>25||strlen($password)<6) {
						 	echo $message = "Password must be 6-25 characters long";
						}else{
							
							require_once("dbConnect.php");
							if($db_server){
								
								$username = clean_string($db_server, $username);
								$password = clean_string($db_server, $password);$repeatpassword = clean_string($db_server, $repeatpassword);
							
								mysqli_select_db($db_server, $db_database);
							
							
								$query="SELECT username FROM users WHERE username='$username'";
								$result=mysqli_query($db_server, $query);
							
								if ($row = mysqli_fetch_array($result)){
									echo $message = "Username already exists. Please try again.";
									
								}else{
									
									$password = salt($password);
									$query = "INSERT INTO users (username, password) VALUES ('$username', '$password')";
									mysqli_query($db_server, $query) or die("Insert failed. ". mysqli_error($db_server));
									echo "you are registered";
									
								}
									
								mysqli_free_result($result);
							}else{
								$message = "Error: could not connect to the database.";
							}
							require_once("db_close.php");
						}
					}
				}
			}
		}
	}
  } else {
	  echo "try recaptcha again";
  }

  
?>

That isn’t the command to connect to the database - you should be using either mysqli_connect or new mysqli with four parameters including the user and password for the database.

http://php.net/manual/en/function.mysqli-connect.php or http://php.net/manual/en/mysqli.quickstart.connections.php

Also there’s no reason for an upperr limit on password length - once ytou use the supplied password function password_hash all passwords whether 6 or 60000000 characters long will all have the same length encrypted value to store in the database.

http://php.net/manual/en/ref.password.php

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.