title: I keep having Uncaught TypeError: mysqli_error(): Argument #1 ($mysql) must be of type mysqli, bool given
body: <p>I would be really grateful if someone can help me solve my problems.
  one of the problems is that when I enter correct data and press submit it keeps showing me this error:</p>
  <pre><code>Fatal error: Uncaught TypeError: mysqli_error(): Argument #1 ($mysql) must be of type mysqli, bool given in /opt/lampp/htdocs/Try_Project/ServerForm.php:70 Stack trace: #0 /opt/lampp/htdocs/Try_Project/ServerForm.php(70): mysqli_error(false) #1 /opt/lampp/htdocs/Try_Project/SignUp.php(16): include('/opt/lampp/htdo...') #2 {main} thrown in /opt/lampp/htdocs/Try_Project/ServerForm.php on line 70
  </code></pre>
  <p>The other is that I can't display all errors which are Duplicate emails, duplicate phone number and the two passwords not matching.</p>
  <p>this is the main signUp code:</p>
  <pre><code>&lt;?php 
  ini_set('display_errors', 1);  
  ini_set('display_startup_errors', 1);
  error_reporting(E_ALL);
  ?&gt;
  &lt;?php
   $duplicateEmail=&quot;&quot;;
   $duplicatePhone=&quot;&quot;;
   $notEqual=&quot;&quot;;
   $insertSuccess=false;
   $emailExist=false;
   $phoneExist=false;
   $passwordER=false;
   ?&gt;
  
  &lt;?php include('ServerForm.php') ?&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;The Silk Flower&lt;/title&gt;
      &lt;meta charset=&quot;utf8&quot;&gt;
      &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;styles1.css&quot;&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;?php include('includes/header.php') ?&gt;
  
       
      &lt;br&gt;
      &lt;br&gt;
      &lt;center&gt;&lt;div&gt;
          
          &lt;?php 
      if($insertSuccess){
      header('location: index.html');
      }
          ?&gt;
           &lt;!-- start of the sign up page --&gt; 
          &lt;h1 class=&quot;title&quot;&gt;Sign up&lt;/h1&gt;
      &lt;/div&gt;
  
          &lt;!-- sign up form --&gt; 
      &lt;form method=&quot;post&quot; action=&quot;&lt;?php $_SERVER['PHP_SELF']?&gt;&quot; name=&quot;login&quot; &gt;
  
    &lt;div class=&quot;container&quot;&gt;
      &lt;label for=&quot;Fname&quot;&gt;&lt;b&gt;First Name&lt;/b&gt;&lt;/label&gt;
      &lt;input type=&quot;text&quot; placeholder=&quot;First Name&quot; name=&quot;Fname&quot; autofocus required&gt;
      
      &lt;label for=&quot;Lname&quot;&gt;&lt;b&gt;Last Name&lt;/b&gt;&lt;/label&gt;
      &lt;input type=&quot;text&quot; placeholder=&quot;Last Name&quot; name=&quot;Lname&quot; required&gt;
      
      &lt;label for=&quot;email&quot;&gt;&lt;b&gt;Email&lt;/b&gt;&lt;/label&gt;
      &lt;input type=&quot;email&quot; placeholder=&quot;Enter Email&quot; name=&quot;email&quot; required&gt;
  
      &lt;label for=&quot;psw&quot;&gt;&lt;b&gt;Password&lt;/b&gt;&lt;/label&gt;
      &lt;input type=&quot;password&quot; placeholder=&quot;Enter Password&quot; name=&quot;psw&quot; minlength=&quot;8&quot;  required&gt;
      
      &lt;label for=&quot;psww&quot;&gt;&lt;b&gt;Confirm Password&lt;/b&gt;&lt;/label&gt;
      &lt;input type=&quot;password&quot; placeholder=&quot;Re-enter Password&quot; name=&quot;psww&quot; minlength=&quot;8&quot;  required&gt;
      
      &lt;label for=&quot;t&quot;&gt;&lt;b&gt;Phone&lt;/b&gt;&lt;/label&gt;
      &lt;input type =&quot;tel&quot; placeholder=&quot;eg. 0500000000&quot; name = &quot;t&quot; required pattern=&quot;[0]{1}[5]{1}[0-9]{8}&quot; maxlength=&quot;10&quot;&gt;
      
      &lt;label for=&quot;add&quot;&gt;&lt;b&gt;Address&lt;/b&gt;&lt;/label&gt;
      &lt;input type=&quot;text&quot; placeholder=&quot;Address&quot; name=&quot;add&quot; maxlength=&quot;60&quot; required&gt;
      
          &lt;div class=&quot;product&quot;&gt;
              &lt;button style=&quot;width: auto&quot; type=&quot;submit&quot; name = &quot;submit&quot;&gt;Sign up&lt;/button&gt;
        &lt;/div&gt;
        &lt;?php
          if($emailExist){
          print(&quot;&lt;br&gt;&lt;p style='color:red; margin-left:10px;'&gt;&quot;. $duplicateEmail.&quot; &lt;/p&gt;&quot;);}
           if ($phoneExist){
                 print(&quot;&lt;br&gt;&lt;p style='color:red; margin-left:10px;'&gt;&quot;. $duplicatePhone.&quot; &lt;/p&gt;&quot;);}
           if ($passwordER){
                 print(&quot;&lt;br&gt;&lt;p style='color:red; margin-left:10px;'&gt;&quot;. $notEqual.&quot; &lt;/p&gt;&quot;);}
          ?&gt; 
  
    &lt;/div&gt;
  &lt;/form&gt;
  &lt;/center&gt;
   &lt;p&gt; 
      
            &lt;strong&gt; &lt;a href = &quot;#top&quot;&gt; &lt;img src=&quot;images/arrowtop.png&quot; width=&quot;40&quot; height=&quot;40&quot;&gt;
                &lt;/a&gt;&lt;/strong&gt;
           &lt;/p&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>and this is code for inserting into the database:</p>
  <pre><code>&lt;?php 
  ini_set('display_errors', 1);  
  ini_set('display_startup_errors', 1);
  error_reporting(E_ALL);
  ?&gt;
   &lt;?php
  // connect to the database
  include('includes/db.php');   
  
  if($_SERVER[&quot;REQUEST_METHOD&quot;] == &quot;POST&quot;){
      
      
  if(isset($_POST['submit'])){
      $Fname=$_POST['Fname'];  
      $Lname=$_POST['Fname'];  
      $email=trim($_POST['email']); 
      $psw=trim($_POST['psw']);
      $psww=trim($_POST['psww']);
      $t=trim($_POST['t']);
      $add=trim($_POST['add']);
  
      $duplicateEmail=false;
      $emailExist=false;
      $duplicateEmail=&quot;&quot;;
      
      $duplicatePhone=false;
      $phoneExist=false;
      $duplicatePhone=&quot;&quot;;
      
      $notEqual=false;
      $passwordEr=false;
      $notEqual=&quot;&quot;;
     
      $checkexistemail=&quot;SELECT Email FROM Users WHERE Email='&quot; .$_POST[&quot;email&quot;].&quot;'&quot;;
      $checkexistphone=&quot;SELECT Pnumber FROM Users WHERE Pnumber='&quot; .$_POST[&quot;t&quot;].&quot;'&quot;;
      $result2 = mysqli_query($db,$checkexistemail);
      $result3 = mysqli_query($db,$checkexistphone);
   
      if (!($result2) || !($result3))
           {
           print (&quot;&lt;p&gt; Query couldn't be executed &lt;/p&gt;&quot;);
           echo mysqli_error($result2);
           echo mysqli_error($result3);
           }
       if (mysqli_num_rows($result2)&gt;0){
           $emailExist=true;
           $duplicateEmail=&quot;This email address already exists, please enter a new one.&quot;;
           }
       if (mysqli_num_rows($result3)&gt;0){
          $phoneExist=true;
          $duplicatePhone=&quot;This Phone number already exists, please enter a new one.&quot;;
      }
      if($psw != $psww){
          $passwordEr=true;
          $notEqual=&quot;The two passwords do not match.&quot;;
      }
      else{
          $insertSuccess=false;
            //insert user data into database
      $query=&quot;INSERT INTO 'Users'('Fname', 'Lname', 'Email', 'Password', 'Pnumber', 'Address') 
                VALUES('$Fname', '$Lname', '$email','$psw', '$t', '$add)&quot;;
  
          
          $insertResult = mysqli_query($db,$query);
          if($insertResult){
              $insertSuccess=true;
          }
          else{
              echo mysqli_error($insertResult);
          }     
           }
      }
            
  }
  else{
          echo mysqli_error($db);   
          $duplicateEmail=&quot;&quot;;
          $duplicatePhone=&quot;&quot;;
  }
      mysqli_close($db);
  ?&gt;
  </code></pre>