#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    120
    Rep Power
    2

    Requires resource, boolean given ...


    I'm getting all the errors today for some reason. So I'm getting this error,

    Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in...

    Yet I have the code set up the same way I do it for another page that doesn't get this error so now I'm confused. I looked the code over, moved it around and then ended up putting it back to where I had it originally and still getting this error. Was wondering if someone could look through my code and see what I might be doing wrong. Thanks for your time.

    PHP Code:
    function special_data($id){
        
    $id = (int)$id;
        
        
    $args func_get_args();
        
    $fields '`'.implode('`, `'$args).'`';
        
        
    $query mysql_query("SELECT $fields FROM `specialspage` WHERE `id`='$id'");
    // it says the error is on this line...
        
    $query_result mysql_fetch_assoc($query);
        foreach (
    $args as $field) {
            
    $args[$field] = $query_result[$field];
        }
        return 
    $args;
    }

    $id $_GET['id'];

    $data special_data($id'name''store''description''description2'); 
  2. #2
  3. No Profile Picture
    Dazed&Confused
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2002
    Location
    Tempe, AZ
    Posts
    506
    Rep Power
    128
    PHP Manual:
    mysql_query() will also fail and return FALSE if the user does not have permission to access the table(s) referenced by the query.
    Also you should move to using mysqli_* or PDO. The mysql_ functions are deprecated as of PHP 5.5.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    120
    Rep Power
    2
    Oh ok thanks for the advice, so is mysqli_ and PDO the same as mysql_

    also there is a check set up so that if the user doesn't have permission to access the page that it header locates to another page however the whole page is accessible being the user I have logged in which makes sense because this user has an administrator persmission which is set to 1 and if they didn't have permission the admin column would be 0. So I don't think thats the issue. Just frustrated because I'm not sure what the issue is then, since this is exacly how I code the other pages which all work fine.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    120
    Rep Power
    2
    Oh I figured it out I had to change the code to reflect this,

    $args = func_get_args();
    unset($args[0]);
    $fields = '`'.implode('`, `', $args).'`';

    But I'm interested in the new way of doing mysql_ so if I use mysql_query right now, how would I use PDO, is there a tutorial you could direct me to? Thanks for your time.
  8. #5
  9. No Profile Picture
    Dazed&Confused
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2002
    Location
    Tempe, AZ
    Posts
    506
    Rep Power
    128
    php.net usually has sufficient examples to get started. Google is your friend.
  10. #6
  11. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    120
    Rep Power
    2
    Thanks for the link and heads up!

IMN logo majestic logo threadwatch logo seochat tools logo