Jump to content

[SOLVED] mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean


Topshed

Recommended Posts

G'day

 

I am totaly new to php and I have spent a whole morning trying to debug a simple piece of test code and I need some help

 

<?php

      $host = "localhost";

      $account = "root";

      $password = "testing";

      $dbname  = "steam";

 

      //  Make connection to database  If no connection made, display error Message   

  $connect = mysqli_connect($host,$account,$password) OR DIE("Error !! Unable to connect to database");

  echo '<b>Step 1:</b> Connected successfully! <BR>';

 

      // Select database or print error message if unsuccessful

      $db = mysqli_select_db($connect,"$dbname") or die( "Unable to select database ".steam);

      echo '<b>Step 2:</b> Connected to ('.$dbname.') successful!<BR>';

 

      $db="SELECT * FROM lner WHERE br_no = lner";

 

      $result = mysqli_query($connect,$db);

        // it appears to work up to this point !!!! Line 20 coms next

 

      $row = mysqli_fetch_array($result);

?>

Then I get this error:-

 

mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in test-1.php on line 20

 

Please help somebody I cannot believe I am that dumb ?

 

thanks in advance

 

Topshed (Roy) >:(  ???

You need to check your result prior to using it.

 

if ($result = mysqli_query($connect,$db)) {  
  $row = mysqli_fetch_array($result);
}

 

ps: The problem is your query is failing. It should look like....

 

$db = "SELECT * FROM lner WHERE br_no = 'lner'";

Thank you,

 

So simple If you know what your talking about.

 

Can I just ask another question

The book I am working from gives examples for post_gre and that is not helping

 

I believe my code should return one record as the search field "br_no" is unique

 

How can I output that record to screen please

 

Roy..

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.