Thread: Checking $_GET

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

    Join Date
    Dec 2012
    Posts
    64
    Rep Power
    2

    Checking $_GET


    There's probably some simple fundamental solution that I'm missing to solve my problem so please throw me a bone.

    Let's say I have a dynamic url's setup to display user profiles based on a number that corresponds to a particular profile.

    Example: domain.com/?userprofile=5

    Now let's say 6 does not correspond to any userprofile. If you were to manually navigate to domain.com/?userprofile=6 the resulting page would be blank.

    How would I go about checking to see if the sql query corresponding to 6 comes back empty, so that i can either send a redirect or error?


    PHP Code:
    $query mysql_query("SELECT * FROM `users` WHERE `uploadID` = '$uploadID'"); 
    Note: I have have tested numerous values in if statements, such as:

    if(empty($query))
    if($query === 0)

    I have also checked to see if an array holding the query data was empty, which didn't work either.
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,122
    Rep Power
    9398
    You can use mysql_num_rows, or fetch a row (there should be only the one) and check if it is empty.

    Also, please consider switching to PDO or mysqli. They are more effective and can be easier to use but most importantly they're safer.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    64
    Rep Power
    2
    Originally Posted by requinix
    You can use mysql_num_rows, or fetch a row (there should be only the one) and check if it is empty.

    Also, please consider switching to PDO or mysqli. They are more effective and can be easier to use but most importantly they're safer.
    Thanks num rows works perfectly, and i will be converting over to PDO.

IMN logo majestic logo threadwatch logo seochat tools logo