title: {"status":"400","message":"Could not register with provided information"}
body: <p>I am trying to register a user into a SQL database using php. I am not sure why this message is popping up. <code>{"status":"400","message":"Could not register with provided information"}</code> This is what Im using in the url:<a href="http://localhost/iHertzmusic/register.php?username=Bob&amp;password=1234&amp;email=bob@mail.com&amp;fullname=Bob%20John" rel="nofollow noreferrer">http://localhost/iHertzmusic/register.php?username=Bob&amp;password=1234&amp;email=bob@mail.com&amp;fullname=Bob%20John</a>  I it might be the url that is the problem but this worked before I add emailed conformation in STEP 4.  Here is my register.php:</p>
  
  <pre><code>&lt;?php
  
  //Step 1. Delare parms of user info
  // Sucuring information and storing variables
  $username = htmlentities($_REQUEST["username"]);
  $password = htmlentities($_REQUEST["password"]);
  $email = htmlentities($_REQUEST["email"]);
  $fullname = htmlentities($_REQUEST["fullname"]);
  
  // if GET or POST are empty
  if (empty($username) || empty($password) || empty($email) || empty($fullname)) {
    $returnArray["status"] = "400";
    $returnArray["massage"] = "Missing required information";
    echo json_encode($returnArray);
    return;
  
  }
  
  // secure password
  $salt = openssl_random_pseudo_bytes(20);
  $secured_password = sha1($password . $salt);
  
  //Step 2. Build connection
  //Secure way to build conn
  $file = parse_ini_file("../../../iHertzmusic.ini");
  
  // store in php var inf from ini var
  $host = trim($file["dbhost"]);
  $user = trim($file["dbuser"]);
  $pass = trim($file["dbpass"]);
  $name = trim($file["dbname"]);
  
  // include access.php to call func from access.php file
  require ("secure/access.php");
  $access = new access($host, $user, $pass, $name);
  $access-&gt;connect();
  
  // Step 3. Insert user information
  $result = $access-&gt;registerUser($username, $secured_password, $salt, $email, $fullname);
  
  //Successfully registered
  if ($result) {
  
      // got current registered user information and store in user
      $user = $access-&gt;selectUser($username);
  
      // declare information to feedback to user of App as json
      $returnArray["status"] = "200";
      $returnArray["message"] = "Successfully registered";
      $returnArray["id"] = $user["id"];
      $returnArray["username"] = $user["username"];
      $returnArray["email"] = $user["email"];
      $returnArray["fullname"] = $user["fullname"];
  
      // STEP 4. Emailing
      //include email.php
  
      require ("secure/email.php");
      // store all class in $email var
      $email = new email();
  
      // store generated token in $token var
      $token = $email-&gt;generateToken(20);
  
      //save in 'emailTokens' table
      $access-&gt;saveToken("emailTokens", $user["id"], $token);
  
      //refer emailing information
      $details = array();
      $details["subject"] = "Email confirmation on iHertz";
      $details["to"] = $user["email"];
      $details["fromName"] = "Sean O'Neal";
      $details["fromEmail"] = "ihertzmusic432@gmail.com";
  
      // access template file
      $template = $email-&gt;confirmationTemplate();
  
      // replace {token} from confirmationTemplate.html by $token and store all content in $template var
      $template = str_replace("{token}", $token, $template);
  
      $details["body"] = $template;
  
      $email-&gt;sendemail($details);
  
    } else { 
  
      $returnArray["status"] = "400";
      $returnArray["message"] = "Could not register with provided information";
  }
  
  // Step 5. Close connection
  $access-&gt;disconnect();
  
  // Step 6. Json data
  echo json_encode($returnArray);
  
   ?&gt;
  </code></pre>
  
  <p>Notice: Undefined variable: returnArray in </p>
  
  <pre><code>
      // Select user information
       public function selectUser($username) {
  
      // sql command
      $sql = "SELECT * FROM users WHERE username'".$username."'";
  
      // assign result we got from $sql to $result var
      $result = $this-&gt;conn-&gt;query($sql);
  
      // if we have at least 1 result returned
      if ($result != null &amp;&amp; (mysqli_num_rows($result) &gt;= 1 )) {
  
        // assign result we got to $row as accociative array
        $row = $result-&gt;fetch_array(MYSQLI_ASSOC);
  
        if (!empty($row)) {
          $returnArray = $row;
        }
      }
  
      return $returnArray;
  }
  </code></pre>
  
  <p>Notice: Undefined variable: charactersLength</p>
  
  <pre><code>function generateToken($length) {
  
    // some characters
    $characters = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890";
  
    // get length of characters string
    $characters = strlen($characters);
  
    $token = '';
  
    // generate random char from $characters every time until it is less than $charactersLength
    for ($i = 0; $i &lt; $length; $i++) {
      $token .=$characters[rand(0, $charactersLength-1)];
     }
  
    return $token;
  
   }
  </code></pre>