Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Mar 2008
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    MySQL and PHP trouble

    This codes third line is give an error message on all pages of my web site.

    <?
    $sql = "SELECT * FROM tb_config WHERE item='click' and howmany='1'";
    $result = mysql_query($sql);
    $row = mysql_fetch_array($result);
    ?>


    The error message says the following

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/moneybux/public_html/index.php on line (number of line on page)

    Can someone help me out to resolve this issue please.

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    This is because your query is failing. You need to do some error checking.
    PHP Code:
    <?php
    $sql 
    "SELECT * FROM tb_config WHERE item='click' and howmany='1'";
    $result mysql_query($sql) or die('The error was: ' mysql_error() .'<br>The query was: ' $sql);
    $row mysql_fetch_array($result);
    ?>
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Regular Coder
    Join Date
    Jun 2006
    Location
    UK
    Posts
    911
    Thanks
    302
    Thanked 2 Times in 2 Posts
    Apparently there isnt any matching records in the table.

  • #4
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Quote Originally Posted by cancer10 View Post
    Apparently there isnt any matching records in the table.
    No matching records would still return a result set of zero and $result would be a valid result resource. Test it by running a query on an expected zero result set. Confirm by testing for mysql_num_rows($result) == 0;.


  •  

    Posting Permissions

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