By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,084 Members | 1,956 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,084 IT Pros & Developers. It's quick & easy.

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

P: n/a
Hello I keep getting a warning ...
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
resource in "name of my php file" when I run this query....
SELECT Menu_Item, Quantity
FROM restorder_item
WHERE Order_Number =58
The code I use to do it is....
$query = "select Menu_Item, Quantity from restorder_item";
$query .= " where Order_Number = ".$_REQUEST["OrderNumber"];

$result = mysql_query($query) or die($query." failed: ".mysql_error());

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
var_dump($row);
}
Notice to test it I did a var_dump of $row and it came back with the
expected results namely......
array(2) { ["Menu_Item"]=> string(1) "3" ["Quantity"]=> string(1) "5" }
So I can't see whats wrong. Everything seems to be working yet I get a
warning.
I have done a quick fix by putting an @ in front of the offending function
but I would really like to know what the problem is.
Thanks for your help in advance.
Noel
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Please don't er with this question. I am pretty sure I have made a mistake
in the query somewhere.
Noel
"Noel Wood" <re******************@optusnet.com.au> wrote in message
news:41***********************@news.optusnet.com.a u...
Hello I keep getting a warning ...
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in "name of my php file" when I run this query....
SELECT Menu_Item, Quantity
FROM restorder_item
WHERE Order_Number =58
The code I use to do it is....
$query = "select Menu_Item, Quantity from restorder_item";
$query .= " where Order_Number = ".$_REQUEST["OrderNumber"];

$result = mysql_query($query) or die($query." failed: ".mysql_error());

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
var_dump($row);
}
Notice to test it I did a var_dump of $row and it came back with the
expected results namely......
array(2) { ["Menu_Item"]=> string(1) "3" ["Quantity"]=> string(1) "5" }
So I can't see whats wrong. Everything seems to be working yet I get a
warning.
I have done a quick fix by putting an @ in front of the offending function
but I would really like to know what the problem is.
Thanks for your help in advance.
Noel

Jul 17 '05 #2

P: n/a
"Noel Wood" <re******************@optusnet.com.au> wrote in message
news:41***********************@news.optusnet.com.a u...
Hello I keep getting a warning ...
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in "name of my php file" when I run this query....
SELECT Menu_Item, Quantity
FROM restorder_item
WHERE Order_Number =58
The code I use to do it is....
$query = "select Menu_Item, Quantity from restorder_item";
$query .= " where Order_Number = ".$_REQUEST["OrderNumber"];

$result = mysql_query($query) or die($query." failed: ".mysql_error());

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
var_dump($row);
}
Notice to test it I did a var_dump of $row and it came back with the
expected results namely......
array(2) { ["Menu_Item"]=> string(1) "3" ["Quantity"]=> string(1) "5" }
So I can't see whats wrong. Everything seems to be working yet I get a
warning.
I have done a quick fix by putting an @ in front of the offending function
but I would really like to know what the problem is.
Thanks for your help in advance.


Your testing for errors leaves a lot to be disired. You only check to see if
mysql.error is set and don't check to see if a results set has been
returned, or that result set actually contains rows.

$result = mysql_query($query);
if(! $result || mysql_error() || mysql_num_rows($result) < 1)
{
echo sprintf('%s rows, [%s] , error: %s',
@mysql_num_rows($result),
$query,
mysql_error());
exit;
}
Note the @ on the front of the second mysql_num_rows. If the result set is
empty then trying to use mysql_num_rows will generate the error that you are
seeing, so you should suppress it.
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Browse more PHP Questions on Bytes