title: Function not working correctly
body: <p>please can someone help me with my code.  I have been at this all day and so close to giving up.</p>
  
  <p>The form displays:
  checkfields are not empty
  This is expected... 
  It continues through the function checkUser() below:</p>
  
  <pre><code>    global $mysqli_db;
      global $db_table;
      //Check the field userName is the same as the Posted Username
      $Field = "userName"; //The Field to check
      $query = "SELECT $Field WHERE $Field=$userNameCheck FROM $db_table LIMIT 1"; 
      $result = mysqli_query($mysqli_db, $query) or die(mysql_error());
  
      echo "The result of the checkUser is:&lt;br&gt;";
      echo $result;
      echo "&lt;br&gt;";
  
      if (!$row = mysqli_fetch_array($result) or die(mysql_error()))
      {
          echo "username was not found in the field in the table&lt;BR&gt;";
          return false; //username was not found in the field in the table
      }
  </code></pre>
  
  <p>The field is the database field within my table $db_table.  I just put it as a variable for simplicity.  I want the next echo to say the result of the checkuser is:
  But it does not get that far so I guess I have an error between my $field and $result?
  Hope this is clearer, apologies long day.</p>
  
  <pre><code> &lt;?php
  //Main Code Sequence
  error_reporting(-1);
  ini_set('display_errors',1);
  
  //Database Setup
  $db_host = "***";
  $db_name = "***";
  $db_table = "emailUser";
  $db_username = "***";
  $db_password = "***";   
  $mysqli_db = new mysqli($db_host,$db_username,$db_password,$db_name);
  
  function webmailSignUp()
  {
      global $mysqli_db;
      global $db_table;
      $webmailFullName = $_POST['webmailFullName'];
      $webmailUserName = $_POST['webmailUserName'];
      $webmailExEmail = $_POST['webmailExEmail'];
      $webmailPhone = $_POST['webmailPhone'];
      $webmailDOB = $_POST['webmailDOB'];
  
      //Check that the fields are not empty
      echo "check";
      if ((empty($webmailFullName)) or (empty($webmailUserName)) or (empty($webmailExEmail)) or (empty($webmailPhone)) or (empty($webmailDOB)))
      {
          echo "One of your fields are blank!  Please try again&lt;BR&gt;";
      }
      else
      {
          echo "fields are not empty&lt;BR&gt;";
          //Check that there is no existing name in the table
          if (checkUser($webmailUserName) == false)
          {
              echo "Result is &lt;BR&gt;";
              echo checkUser($webmailUserName);
              //Adding the person to the Database Query   
              //$query = "INSERT INTO $db_table(userFullName,userName,userExEmail,userPhone,userDOB) VALUES(?,?,?,?,?)";
              //Binding to Prevent SQL injection                      
              //$requery = $mysqli_db-&gt;prepare($query);
              //$requiry-&gt;bind_param($webmailFullName,$webmailUserName,$webmailExEmail,$webmailPhone,$webmailDOB);
              //if ($requery-&gt;execute())
              //{
              //  echo "Person has been added";
              //}
              //else
              //{
              //  echo "bind failed";
              //} 
          }
          else
          {
              echo "There is already a user registered with this username.  Please try a different one.&lt;BR&gt;";
          }
      }
  }
  
  function checkUser($userNameCheck)
  {
      global $mysqli_db;
      global $db_table;
      //Check the field userName is the same as the Posted Username
      $Field = "userName"; //The Field to check
      $query = "SELECT $Field WHERE $Field=$userNameCheck FROM $db_table LIMIT 1"; 
      $result = mysqli_query($mysqli_db, $query) or die(mysql_error());
  
      echo "The result of the checkUser is:&lt;br&gt;";
      echo $result;
      echo "&lt;br&gt;";
  
      if (!$row = mysqli_fetch_array($result) or die(mysql_error()))
      {
          echo "username was not found in the field in the table&lt;BR&gt;";
          return false; //username was not found in the field in the table
      }
      else
      {
          echo "username was found in the field in the table&lt;BR&gt;";
          return true; //username was found in the field in the table
      }
  }
  
  function db_close()
  {
      global $mysqli_db;
      $mysqli_db-&gt;close();
  }
  
  if(isset($_POST['webmailRegisterSubmit']))
  {
      webmailSignUp();
      db_close();
      echo "End of Registration";
  }
  if(isset($_POST['webamilForgottenPWSubmit']))
  {
      webmailForgottenPassword();
      db_close();
      echo "End of Password Reset Request";
  }
  ?&gt;
  </code></pre>