title: Warning: mysqli_real_escape_string(): Couldn't fetch mysqli
body: <p>Warning: mysqli_real_escape_string(): Couldn't fetch mysqli in /Applications/XAMPP/xamppfiles/htdocs/try/register.php on line 6</p>
  
  <p>Warning: mysqli_real_escape_string(): Couldn't fetch mysqli in /Applications/XAMPP/xamppfiles/htdocs/try/register.php on line 7</p>
  
  <p>Warning: mysqli_real_escape_string(): Couldn't fetch mysqli in /Applications/XAMPP/xamppfiles/htdocs/try/register.php on line 8</p>
  
  <p>Warning: mysqli_real_escape_string(): Couldn't fetch mysqli in /Applications/XAMPP/xamppfiles/htdocs/try/register.php on line 9</p>
  
  <p>Warning: mysqli_query(): Couldn't fetch mysqli in /Applications/XAMPP/xamppfiles/htdocs/try/register.php on line 12        </p>
  
  <p>REGISTER.PHP</p>
  
  <pre><code>&lt;?php
        $output=NULL;
        if (isset($_POST['submit'])) {
          include 'config.php';
  
          $name = mysqli_real_escape_string($conn, $_POST['name']); //this is LINE 6
          $email = mysqli_real_escape_string($conn, $_POST['email']); // LINE 7
          $username = mysqli_real_escape_string($conn, $_POST['username']); //LINE 8
          $password = mysqli_real_escape_string($conn, $_POST['password']); //LINE 9
  
         $query= "SELECT * FROM users WHERE username= '$username'";
          $result= mysqli_query($conn, $query); //LINE 12
  
          if (empty($name) || empty($email) || empty($username) || empty($password)) {
            $output= "please all the fields";
          } elseif (mysqli_num_rows($result)!=0) {
              $output= 'the username is already taken';
          } elseif (strlen($password)&lt;8) {
              $output= "your must be atleast 8 characters";
          } else {
            // insert the record.
            $insert = mysqli_query($conn, "INSERT INTO users(name, email, username, password)
              VALUES ('$name', '$email', '$username', '$password')");
  
              if ($insert != TRUE) {
                $output= 'there was a problem '. mysqli_error();
              } else {
                 $output= "record was successfully created " ;
              }
          }
  
        }
  
  
      /*if (isset($_POST['name']) &amp;&amp; isset($_POST['email']) &amp;&amp; isset($_POST['username']) &amp;&amp; isset($_POST['password'])){
          $name = $_POST['name'];
          $email = $_POST['email'];
          $username=$_POST['username'];
          $password = $_POST['password'];
  
       $query= "INSERT INTO users (name, email, username, password
                VALUES ('{$name}', '{$email}', '{$username}', '{$password}')";
  
        $result = mysqli_query($conn, $query);
  
          if ($result) {
            echo "user created successfuly.";
          } else {
            die ("user registeration failed".mysqli_error());
          }
        }*/
       ?&gt;
      &lt;!DOCTYPE html&gt;
      &lt;html&gt;
        &lt;head&gt;
          &lt;meta charset="utf-8"&gt;
          &lt;title&gt;testing site&lt;/title&gt;
        &lt;/head&gt;
        &lt;body&gt;
         &lt;form method="POST"&gt;
           &lt;table&gt;
             &lt;p&gt;Fill the Registration form below&lt;/p&gt;
             &lt;tr&gt;
               &lt;td&gt;Name: &lt;/td&gt;
               &lt;td&gt; &lt;input type="name" name="name" &gt; &lt;/td&gt;
             &lt;/tr&gt;
             &lt;tr&gt;
               &lt;td&gt;Email: &lt;/td&gt;
               &lt;td&gt;   &lt;input type="email" name="email"&gt; &lt;/td&gt;
             &lt;/tr&gt;
             &lt;tr&gt;
               &lt;td&gt;Username: &lt;/td&gt;
               &lt;td&gt;&lt;input type="text" name="username"&gt; &lt;/td&gt;
             &lt;/tr&gt;
             &lt;tr&gt;
               &lt;td&gt;Password: &lt;/td&gt;
               &lt;td&gt;&lt;input type="password" name="password"&gt; &lt;/td&gt;
             &lt;/tr&gt;
             &lt;tr&gt;
               &lt;td&gt;&lt;input type="submit" name="submit" value="Register"&gt;
                    &lt;input type="reset" value="Reset"&gt;
               &lt;/td&gt;
             &lt;/tr&gt;
  
           &lt;/table&gt;
  
  
         &lt;/form&gt;
        &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>
  
  <p>CONFIG.PHP</p>
  
  <pre><code>&lt;?php
  $server='localhost';
  $dbuser='root';
  $dbpass="";
  $dbname="testing";
  
  
  
  $conn =mysqli_connect($server,$dbuser, $dbpass, $dbname);
  
    if (mysqli_connect_errno()) {
      die ("database connection failed"
        . mysqli_connect_error());
    }
  
  mysqli_close($conn);
   ?&gt;
  </code></pre>