Results 1 to 4 of 4

Thread: mysql resource error?

  1. #1
    Senior Member
    Join Date
    May 2010
    Posts
    98

    Default mysql resource error?

    Hi all,

    I've started to construct php code in NOF to read an sql database (ive used Chucks tutorial, thanks Chuck)

    The code snippet i am using is as follows (ive not included all the username, password stuff etc):

    $query="SELECT * FROM business_cards";
    $result=mysql_query($query);
    $num_results = mysql_num_rows($result);

    Everything is fine until i get the following message:

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

    I have also tried substituting this line for mysql_fetch_assoc($result)) and still get not a valid MySQL result resource

    Any ideas please?

    Regards, J

  2. #2
    Senior Member chuckj's Avatar
    Join Date
    Jan 2010
    Location
    www.beyondfusion.com - Florida
    Posts
    1,302

    Default

    Are you connecting to the database prior to the code you listed?

    db_connect();

    And you'll need to do an echo to see the number of rows.

    echo "$num_results";
    Chuck Joslin
    www.BeyondFusion.com
    PHP & MySQL development with Fusion
    Fusion support for AllWebMenus (Likno) Contact me for custom AWM menus for your sites.
    Tutorials and Forums

  3. #3
    Senior Member
    Join Date
    Apr 2010
    Posts
    352

    Default

    It's hard to tell with only the code you've shown here but, a couple of questions/soloutions:

    Have you run something similar to connect to the database first?
    Code:
    $db_connect=mysql_connect("localhost/where ip to connect to","username","password") or die ("Could not connect to database"); mysql_select_db("your database") or die ("Could not select database!");
    and/or

    Add an or die() line to your line $result = mysql_query($query); - $result = mysql_query($query) or die (mysql_error()."<br />Can't execute query: $query");

  4. #4
    Senior Member
    Join Date
    May 2010
    Posts
    98

    Default

    Thanks Andrew, the check on $result confirmed that i had miss spelt my table name! - as simple as that

    All working fine now

    Regards, J

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •