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

supplied argument is not a valid MySQL result resource

P: n/a
Before I get in trouble, I have searched extensively for this one, in the
PHP Docs, online etc.

I have a simple page:

<?php

$un="jim";
$pw="jim";
$db="localhost";

$link = mysql_connect($db,$un,$pw) or die("Could not connect: " .
mysql_error());

$sql2 = "SELECT * FROM eib.book ORDER BY bookid";
$op = mysql_query($sql2) ;
$num= mysql_numrows($op);

?>

When I run the page I keep getting this error:

Warning: mysql_numrows(): supplied argument is not a valid MySQL result
resource in C:\Program Files\Apache
Group\Apache2\htdocs\eib\php\itemadd2.php on line 34

I can't work out why?

The code looks fine to me.

Thanks

Jim
http://jimpix.co.uk


Jul 17 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
I noticed that Message-ID: <br*********@titan.btinternet.com> from
Burton Figg contained the following:
$sql2 = "SELECT * FROM eib.book ORDER BY bookid";

What have you tried?
Does this query work in phpMyadmin?
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #2

P: n/a
Burton Figg wrote:
$sql2 = "SELECT * FROM eib.book ORDER BY bookid";
$op = mysql_query($sql2) ;
Try
$op = mysql_query($sql2) or die(mysql_error() . ' in ' . $sql2);

$num= mysql_numrows($op);
Shouldn't this be
$num = mysql_num_rows($op);
## _____________^__________

<quote src="http://pt2.php.net/manual/en/function.mysql-num-rows.php">
.. For downward compatibility mysql_numrows() can also be used.
This is deprecated however.
</quote>

When I run the page I keep getting this error:

Warning: mysql_numrows(): supplied argument is not a valid MySQL result
resource in C:\Program Files\Apache
Group\Apache2\htdocs\eib\php\itemadd2.php on line 34

I can't work out why?

The code looks fine to me.


It looks fine to me too :)
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #3

P: n/a
On Sat, 13 Dec 2003 21:42:29 +0000, Burton Figg wrote:
Before I get in trouble, I have searched extensively for this one, in the
PHP Docs, online etc.

I have a simple page:

<?php

$un="jim";
$pw="jim";
$db="localhost";

$link = mysql_connect($db,$un,$pw) or die("Could not connect: " .
mysql_error());

$sql2 = "SELECT * FROM eib.book ORDER BY bookid";
$op = mysql_query($sql2) ;
$num= mysql_numrows($op);

?>

When I run the page I keep getting this error:

Warning: mysql_numrows(): supplied argument is not a valid MySQL result
resource in C:\Program Files\Apache
Group\Apache2\htdocs\eib\php\itemadd2.php on line 34

I can't work out why?


mysql_select_db ;)

Jul 17 '05 #4

P: n/a
CJ Llewellyn wrote:
On Sat, 13 Dec 2003 21:42:29 +0000, Burton Figg wrote:
$sql2 = "SELECT * FROM eib.book ORDER BY bookid";
$op = mysql_query($sql2) ;
mysql_select_db ;)


No need for that.

select <fields> from database.table ...

You can specify the database in the query string; you can even (luckily)
mix different databases in the same query:

select u.name, x.quantity from db1.tb1 u, db2.tb2 x where u.id=x.id
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #5

P: n/a
On Sat, 13 Dec 2003 21:42:29 +0000 (UTC), "Burton Figg" <so*****@somewhere.com>
wrote:
Before I get in trouble, I have searched extensively for this one, in the
PHP Docs, online etc.
Really? The first few pages on Google web and groups searches come up with the
answer.
$link = mysql_connect($db,$un,$pw) or die("Could not connect: " .
mysql_error());
Here you correctly check for a possible error and stop the script going any
further.
$sql2 = "SELECT * FROM eib.book ORDER BY bookid";
$op = mysql_query($sql2) ;
Here you haven't bothered...
$num= mysql_numrows($op);
... resulting in you passing 'false' to mysql_numrows.
When I run the page I keep getting this error:
Warning, actually, you skipped passed the point at which you got an error
(mysql_query) because you didn't check for it
Warning: mysql_numrows(): supplied argument is not a valid MySQL result
resource in C:\Program Files\Apache
Group\Apache2\htdocs\eib\php\itemadd2.php on line 34


--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 17 '05 #6

P: n/a
On Sat, 13 Dec 2003 22:18:56 +0000, Pedro Graca wrote:
CJ Llewellyn wrote:
On Sat, 13 Dec 2003 21:42:29 +0000, Burton Figg wrote:
$sql2 = "SELECT * FROM eib.book ORDER BY bookid";
$op = mysql_query($sql2) ;

mysql_select_db ;)


No need for that.


Call me fussy, but I like to know I've got access to the database before I
try to use it :)

Jul 17 '05 #7

P: n/a
CJ Llewellyn wrote:
On Sat, 13 Dec 2003 22:18:56 +0000, Pedro Graca wrote:
CJ Llewellyn wrote:
mysql_select_db ;)
No need for that.
Call me fussy, but I like to know I've got access to the database before I
try to use it :)


fussy!

call me fussy too :)

mysql_select_db() or die();
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #8

P: n/a
"Burton Figg" a écrit le 13/12/2003 :
$sql2 = "SELECT * FROM eib.book ORDER BY bookid";
$op = mysql_query($sql2) ;
$num= mysql_numrows($op);


Are you sure a table name containing a dot is OK? I won't risk it
myself. Cause 'eib.book' can be translated by MySQL as field book form
table eib...

What does this select returns directly in phpmyadmin or equivalent ?

--
Have you read the manual?
http://www.php.net/manual/en/

Jul 17 '05 #9

P: n/a
Jedi121 <je*********@free.fr.Removethis> brightened my day with his
incisive wit when in news:mesnews.701d7d3c.cb834ecb.367.2689
@free.fr.Removethis he conjectured that:
"Burton Figg" a écrit le 13/12/2003 :
$sql2 = "SELECT * FROM eib.book ORDER BY bookid";
$op = mysql_query($sql2) ;
$num= mysql_numrows($op);


Are you sure a table name containing a dot is OK? I won't risk it
myself. Cause 'eib.book' can be translated by MySQL as field book form
table eib...


eh? The table name doesn't have a dot in it. He's merely using fully
qualified column names in form "tablename<dot>columnName" isn't he?
Jul 17 '05 #10

P: n/a
With total disregard for any kind of safety measures Walter Mitty
<mi******@yahoo.co.uk> leapt forth and uttered:
Jedi121 <je*********@free.fr.Removethis> brightened my day with
his incisive wit when in news:mesnews.701d7d3c.cb834ecb.367.2689
@free.fr.Removethis he conjectured that:
"Burton Figg" a écrit le 13/12/2003 :
$sql2 = "SELECT * FROM eib.book ORDER BY bookid";
$op = mysql_query($sql2) ;
$num= mysql_numrows($op);


Are you sure a table name containing a dot is OK? I won't risk
it myself. Cause 'eib.book' can be translated by MySQL as field
book form table eib...


eh? The table name doesn't have a dot in it. He's merely using
fully qualified column names in form "tablename<dot>columnName"
isn't he?


databasename<dot>tablename

--
There is no signature.....
Jul 17 '05 #11

P: n/a
Phil Roberts <ph*****@HOLYflatnetSHIT.net> brightened my day with his
incisive wit when in news:Xn*************************@206.127.4.22 he
conjectured that:
With total disregard for any kind of safety measures Walter Mitty
<mi******@yahoo.co.uk> leapt forth and uttered:
Jedi121 <je*********@free.fr.Removethis> brightened my day with
his incisive wit when in news:mesnews.701d7d3c.cb834ecb.367.2689
@free.fr.Removethis he conjectured that:
"Burton Figg" a écrit le 13/12/2003 :

$sql2 = "SELECT * FROM eib.book ORDER BY bookid";
$op = mysql_query($sql2) ;
$num= mysql_numrows($op);

Are you sure a table name containing a dot is OK? I won't risk
it myself. Cause 'eib.book' can be translated by MySQL as field
book form table eib...


eh? The table name doesn't have a dot in it. He's merely using
fully qualified column names in form "tablename<dot>columnName"
isn't he?


databasename<dot>tablename


woops. I meant this. sorry.
Jul 17 '05 #12

P: n/a
>> databasename<dot>tablename

Then he should check for MySQL version 'cause MySQL manual state :
"db_name.tbl_name.col_name = Column col_name from table tbl_name of the
database db_name. This form is available in MySQL Version 3.22 or
later."

--
Have you read the manual?
http://www.php.net/manual/en/

Jul 17 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.

Browse more PHP Questions on Bytes