PHP Beginner with unknown fetch array error....help please!

Hi
I hope this is the right place to post.

I’m trying to install a server-side church rota management tool on a website. A colleague installed it on his website without any issues - we then tried on my site (did exactly the same method) and we’re getting an error message that we just can’t work out.

Can’t put the link on here but google “DoDifferent Church Rota” and it’s the first link. (it’s free to download if you want to poke around in it).

The error I’m getting is this:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/[…]/rota/includes/functions.php on line 14

I’ve e-mailed and tweeted the creator of this with no response so thought I’d try elsewhere.

Can anyone help me out with what I can do to get rid of this message?

Thanks

Nick

Assume your code follows the basic premise set out below:

[php]$sql = “THIS IS A sql_query OF SORTS”;
$query = mysql_query($sql);
while(($row = mysql_fetch_array($query)) !== false) //erroring line
{[/php]

The line commented above will fail with the mentioned error, if the query in $sql failed. If a query fails, mysql_query() returns boolean false (instead of the expected ‘mysql result resource’). Check the query (existant tables etc) then try again, also try putting after your mysql_query() line:
[php]$query = mysql_query($sql);
if($query === false) echo mysql_error(); //add this line to view mysql’s last reported error[/php]

Hi Smokey

Thanks for getting back to me. I’ve been on paternity leave since I first had this problem, and looking back at it I remember now why I got so confused!

Below is the php code that is causing the error:

[php]if($holdQuery != true) {
$sql = “SELECT * FROM cr_settings”;
$result = mysql_query($sql) or die(mysql_error());
}

while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$owner = $row[‘owner’];
$owneremail = $row[‘siteadminemail’];
}[/php]

It’s the “while…” row that is being flagged in the error message I’m getting.

I tried putting in your line of code (replacing $query with $result) below the $result… line but nothing extra was displayed on the screen.

My colleague seemed to think it all hung on the [php]if ($holdQuery !=true)[/php] line. The only other place that this is mentioned is in the first lines of the initial install.php file where it says:

[php]include(‘includes/dbConfig.php’);
$holdQuery = true;
include(‘includes/functions.php’);[/php]

It’s not possible to run the query it’s saying as the table cr_settings has not yet been created - the table building takes place after these lines of code.

Have you got any other possible help you could offer?

Many Thanks

Nick

Try commenting out the if statement - not forgetting the closing }

Depending on what it is used for, you may just need to include the while loop in the if statement.

Thanks again for the reply.

Commented out these lines:
[php]$sql = “SELECT * FROM cr_settings”;
$result = mysql_query($sql) or die(mysql_error());
}[/php]
The error message wasn’t there but the program did not run properly - not as I saw it run on my colleagues site.

Might have to throw the towel in on this one unless the original developer gets back to me.

Thanks for all your help.

Nick

Sponsor our Newsletter | Privacy Policy | Terms of Service