Warning: mysqli_fetch_array() expects Parameter 1 to be mysqli_result, Boolean Given in

Asked

Viewed 96 times

0

Good afternoon guys, I’m trying to find out why this mistake... I’m grading all the help you can give me;

Warning: mysqli_fetch_array() expects Parameter 1 to be mysqli_result, Boolean Given in C: xampp htdocs[testing] login.php on line 16

Warning: mysqli_num_rows() expects Parameter 1 to be mysqli_result, Boolean Given in C: xampp htdocs[testing] login.php on line 19

I have read several answers but they are not adapted to my situation so I decided to ask, the codes are as follows:

login.php

<?php
   include("config.php");
   session_start();

   if($_SERVER["REQUEST_METHOD"] == "POST") {
      // username and password sent from form 

      //$firstname = mysqli_real_escape_string($con, $_POST['firstname']);
      $myusername = mysqli_real_escape_string($conn,$_POST['username']);
      $mypassword = mysqli_real_escape_string($conn,$_POST['password']);

      // $sql = "SELECT id FROM admin WHERE username = '$myusername' and passcode = '$mypassword'";
      $sql = "SELECT id, linklabel FROM pages ORDER BY pageorder ASC";
      $result = mysqli_query($conn, $sql);
      // $result = mysqli_query($conn,$sql);
      $row = mysqli_fetch_array($result,MYSQLI_ASSOC);
      $active = $row['active'];

      $count = mysqli_num_rows($result);

      // If result matched $myusername and $mypassword, table row must be 1 row

      if($count == 1) {
         session_register("myusername");
         $_SESSION['login_user'] = $myusername;

         header("location: index.html");
      }else {
         $error = "Your Login Name or Password is invalid";
      }
   }
?>

<html>

   <head>
      <title>Login Page</title>

      <style type = "text/css">
         body {
            font-family:Arial, Helvetica, sans-serif;
            font-size:14px;
         }

         label {
            font-weight:bold;
            width:100px;
            font-size:14px;
         }

         .box {
            border:#666666 solid 1px;
         }
      </style>

   </head>

   <body bgcolor = "#FFFFFF">

      <div align = "center">
         <div style = "width:300px; border: solid 1px #333333; " align = "left">
            <div style = "background-color:#333333; color:#FFFFFF; padding:3px;"><b>Login</b></div>

            <div style = "margin:30px">

               <form action = "" method = "post">
                  <label>UserName  :</label><input type = "text" name = "username" class = "box"/><br /><br />
                  <label>Password  :</label><input type = "password" name = "password" class = "box" /><br/><br />
                  <input type = "submit" value = " Submit "/><br />
               </form>
               <div style = "font-size:11px; color:#cc0000; margin-top:10px"></div>
             </div>
          </div>

      </div>

   </body>
</html>

config.php

<?php
$servername = "localhost";
$username = "********";
$password = "********";
$db = "appdbadm";

// Create connection
$conn = mysqli_connect("$servername","$username","$password") or die ("could not connect to mysql");
mysqli_select_db($conn, "appdbadm") or die ("no database"); 
// $conn = new mysqli($servername, $username, $password);
// Check connection
//if ($conn->connect_error) {
//    die("Connection failed: " . $conn->connect_error);
// }
echo "Connected successfully";
?> 
  • 1

    The consultation in mysqli_query() failed, need to verify which is the error.

  • and how I do it?

  • Do so: $result = mysqli_query($conn, $sql) or die(mysqli_error($conn)); this should already display the error, there are more instructions on that link at the top of the question.

  • 1

    Thanks already found with this, was the name of the table!!!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.