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) >:(  ???

Link to comment
Share on other sites

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'";

Link to comment
Share on other sites

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..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.