Jump to content

Archived

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

CMK08

[SOLVED] WHY?- Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result

Recommended Posts

Hello there,

 

Last night I worked on this script on my mac os x and everything was working beautifully. This morning I came to work to test the same script on a windows machine - apache 2.2.8, php 5.2.6, mysql 5.0.51b - and now I get this warning:

 

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\wamp\www\downloads\zipplet.php on line 19

 

Warning: mysqli_free_result() expects parameter 1 to be mysqli_result, boolean given in C:\wamp\www\downloads\zipplet.php on line 27

 

Here is the code:

 

<?PHP
require_once('../connect.php');
//initiates the array to build form

$fileList2 = array();

//this is a place holder for data coming from log in

$user_id=2;

//select query to display only data belonging to current user

$qry = "Select user_name, rpt_name  FROM data_reports_users where user_id=$user_id";

$r = mysqli_query($dbc,$qry);

//retrieve data from query result and put it in $fileList2

while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)){

$fileList2[] = $row['rpt_name'];

	  		  
}


mysqli_free_result($r);

mysqli_close($dbc);

 

Any ideas?

 

Thanks!

Share this post


Link to post
Share on other sites

your query is failing, try replacing this:

$r = mysqli_query($dbc,$qry);

with

$r = mysqli_query($dbc,$qry)
  or die("Error: ".mysqli_error($dbc));

Share this post


Link to post
Share on other sites

Cool! The error reads: "no database selected". It turned out that my "connect.php" file didn't have a database defined. Thank you very much! I will try to always use that line from now on!

:)

 

CMK08

Share this post


Link to post
Share on other sites

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