Connecting Tech Pros Worldwide Forums | Help | Site Map

supplied argument is not a valid MySQL result resource

Burton Figg
Guest
 
Posts: n/a
#1: Jul 17 '05
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





Geoff Berrow
Guest
 
Posts: n/a
#2: Jul 17 '05

re: supplied argument is not a valid MySQL result resource


I noticed that Message-ID: <brg144$rg$1@titan.btinternet.com> from
Burton Figg contained the following:
[color=blue]
> $sql2 = "SELECT * FROM eib.book ORDER BY bookid";[/color]


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/
Pedro Graca
Guest
 
Posts: n/a
#3: Jul 17 '05

re: supplied argument is not a valid MySQL result resource


Burton Figg wrote:[color=blue]
> $sql2 = "SELECT * FROM eib.book ORDER BY bookid";
> $op = mysql_query($sql2) ;[/color]

Try
$op = mysql_query($sql2) or die(mysql_error() . ' in ' . $sql2);

[color=blue]
> $num= mysql_numrows($op);[/color]

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>

[color=blue]
> 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.[/color]

It looks fine to me too :)
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
CJ Llewellyn
Guest
 
Posts: n/a
#4: Jul 17 '05

re: supplied argument is not a valid MySQL result resource


On Sat, 13 Dec 2003 21:42:29 +0000, Burton Figg wrote:
[color=blue]
> 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?[/color]

mysql_select_db ;)

Pedro Graca
Guest
 
Posts: n/a
#5: Jul 17 '05

re: supplied argument is not a valid MySQL result resource


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

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 =--
Andy Hassall
Guest
 
Posts: n/a
#6: Jul 17 '05

re: supplied argument is not a valid MySQL result resource


On Sat, 13 Dec 2003 21:42:29 +0000 (UTC), "Burton Figg" <someone@somewhere.com>
wrote:
[color=blue]
>Before I get in trouble, I have searched extensively for this one, in the
>PHP Docs, online etc.[/color]

Really? The first few pages on Google web and groups searches come up with the
answer.
[color=blue]
>$link = mysql_connect($db,$un,$pw) or die("Could not connect: " .
>mysql_error());[/color]

Here you correctly check for a possible error and stop the script going any
further.[color=blue]
>
> $sql2 = "SELECT * FROM eib.book ORDER BY bookid";
> $op = mysql_query($sql2) ;[/color]

Here you haven't bothered...
[color=blue]
> $num= mysql_numrows($op);[/color]

... resulting in you passing 'false' to mysql_numrows.
[color=blue]
>When I run the page I keep getting this error:[/color]

Warning, actually, you skipped passed the point at which you got an error
(mysql_query) because you didn't check for it
[color=blue]
>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[/color]

--
Andy Hassall (andy@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
CJ Llewellyn
Guest
 
Posts: n/a
#7: Jul 17 '05

re: supplied argument is not a valid MySQL result resource


On Sat, 13 Dec 2003 22:18:56 +0000, Pedro Graca wrote:
[color=blue]
> CJ Llewellyn wrote:[color=green]
>> On Sat, 13 Dec 2003 21:42:29 +0000, Burton Figg wrote:[color=darkred]
>>> $sql2 = "SELECT * FROM eib.book ORDER BY bookid";
>>> $op = mysql_query($sql2) ;[/color][/color]
>[color=green]
>> mysql_select_db ;)[/color]
>
> No need for that.[/color]

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

Pedro Graca
Guest
 
Posts: n/a
#8: Jul 17 '05

re: supplied argument is not a valid MySQL result resource


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

fussy!

call me fussy too :)

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

re: supplied argument is not a valid MySQL result resource


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

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/

Walter Mitty
Guest
 
Posts: n/a
#10: Jul 17 '05

re: supplied argument is not a valid MySQL result resource


Jedi121 <jedi121news@free.fr.Removethis> brightened my day with his
incisive wit when in news:mesnews.701d7d3c.cb834ecb.367.2689
@free.fr.Removethis he conjectured that:
[color=blue]
> "Burton Figg" a écrit le 13/12/2003 :
>[color=green]
>> $sql2 = "SELECT * FROM eib.book ORDER BY bookid";
>> $op = mysql_query($sql2) ;
>> $num= mysql_numrows($op);[/color]
>
> 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...
>[/color]

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?
Phil Roberts
Guest
 
Posts: n/a
#11: Jul 17 '05

re: supplied argument is not a valid MySQL result resource


With total disregard for any kind of safety measures Walter Mitty
<mitticus@yahoo.co.uk> leapt forth and uttered:
[color=blue]
> Jedi121 <jedi121news@free.fr.Removethis> brightened my day with
> his incisive wit when in news:mesnews.701d7d3c.cb834ecb.367.2689
> @free.fr.Removethis he conjectured that:
>[color=green]
>> "Burton Figg" a écrit le 13/12/2003 :
>>[color=darkred]
>>> $sql2 = "SELECT * FROM eib.book ORDER BY bookid";
>>> $op = mysql_query($sql2) ;
>>> $num= mysql_numrows($op);[/color]
>>
>> 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...
>>[/color]
>
> 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?
>[/color]

databasename<dot>tablename

--
There is no signature.....
Walter Mitty
Guest
 
Posts: n/a
#12: Jul 17 '05

re: supplied argument is not a valid MySQL result resource


Phil Roberts <philrob@HOLYflatnetSHIT.net> brightened my day with his
incisive wit when in news:Xns945269F459A0Dphilroberts@206.127.4.22 he
conjectured that:
[color=blue]
> With total disregard for any kind of safety measures Walter Mitty
> <mitticus@yahoo.co.uk> leapt forth and uttered:
>[color=green]
>> Jedi121 <jedi121news@free.fr.Removethis> brightened my day with
>> his incisive wit when in news:mesnews.701d7d3c.cb834ecb.367.2689
>> @free.fr.Removethis he conjectured that:
>>[color=darkred]
>>> "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...
>>>[/color]
>>
>> 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?
>>[/color]
>
> databasename<dot>tablename
>[/color]

woops. I meant this. sorry.
Jedi121
Guest
 
Posts: n/a
#13: Jul 17 '05

re: supplied argument is not a valid MySQL result resource


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

Closed Thread