supplied argument is not a valid MySQL result resource

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Burton Figg

    supplied argument is not a valid MySQL result resource

    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($sq l2) ;
    $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\h tdocs\eib\php\i temadd2.php on line 34

    I can't work out why?

    The code looks fine to me.

    Thanks

    Jim
    The homepage for Jimpix Username Generators - an interesting and unique collection of username generation tools





  • Geoff Berrow

    #2
    Re: supplied argument is not a valid MySQL result resource

    I noticed that Message-ID: <brg144$rg$1@ti tan.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/

    Comment

    • Pedro Graca

      #3
      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($sq l2) ;[/color]

      Try
      $op = mysql_query($sq l2) 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\h tdocs\eib\php\i temadd2.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 =--

      Comment

      • CJ Llewellyn

        #4
        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($sq l2) ;
        > $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\h tdocs\eib\php\i temadd2.php on line 34
        >
        > I can't work out why?[/color]

        mysql_select_db ;)

        Comment

        • Pedro Graca

          #5
          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($sq l2) ;[/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 =--

          Comment

          • Andy Hassall

            #6
            Re: supplied argument is not a valid MySQL result resource

            On Sat, 13 Dec 2003 21:42:29 +0000 (UTC), "Burton Figg" <someone@somewh ere.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($sq l2) ;[/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)

            Comment

            • CJ Llewellyn

              #7
              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($sq l2) ;[/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 :)

              Comment

              • Pedro Graca

                #8
                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 =--

                Comment

                • Jedi121

                  #9
                  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($sq l2) ;
                  > $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?


                  Comment

                  • Walter Mitty

                    #10
                    Re: supplied argument is not a valid MySQL result resource

                    Jedi121 <jedi121news@fr ee.fr.Removethi s> brightened my day with his
                    incisive wit when in news:mesnews.70 1d7d3c.cb834ecb .367.2689
                    @free.fr.Remove this 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($sq l2) ;
                    >> $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?

                    Comment

                    • Phil Roberts

                      #11
                      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@fr ee.fr.Removethi s> brightened my day with
                      > his incisive wit when in news:mesnews.70 1d7d3c.cb834ecb .367.2689
                      > @free.fr.Remove this 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($sq l2) ;
                      >>> $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<do t>tablename

                      --
                      There is no signature.....

                      Comment

                      • Walter Mitty

                        #12
                        Re: supplied argument is not a valid MySQL result resource

                        Phil Roberts <philrob@HOLYfl atnetSHIT.net> brightened my day with his
                        incisive wit when in news:Xns945269F 459A0Dphilrober ts@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@fr ee.fr.Removethi s> brightened my day with
                        >> his incisive wit when in news:mesnews.70 1d7d3c.cb834ecb .367.2689
                        >> @free.fr.Remove this he conjectured that:
                        >>[color=darkred]
                        >>> "Burton Figg" a écrit le 13/12/2003 :
                        >>>
                        >>>> $sql2 = "SELECT * FROM eib.book ORDER BY bookid";
                        >>>> $op = mysql_query($sq l2) ;
                        >>>> $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<do t>tablename
                        >[/color]

                        woops. I meant this. sorry.

                        Comment

                        • Jedi121

                          #13
                          Re: supplied argument is not a valid MySQL result resource

                          >> databasename<do t>tablename

                          Then he should check for MySQL version 'cause MySQL manual state :
                          "db_name.tbl_na me.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?


                          Comment

                          Working...