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

    Join Date
    Jul 2013
    Posts
    8
    Rep Power
    0

    Exclamation $_GET not working properly


    Hello,
    i got a problem with $_GET[]. please see the below code and help me.

    <?php
    if(isset($_GET['_rp'])==1)
    {
    echo '1';
    }
    else if(isset($_GET['_rp'])==1)
    {
    echo '2';
    }
    ?>
    when i'm changing the value of _rp=2 it was showing the result as '1' but not '2'. Why this was happening please help me to solve..
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1046
    Um, please take a close look at your code. This makes no sense.

    First of all, you have the same condition twice, so the elseif (one word!) part will never be executed. Secondly, you check the return value of isset($_GET['_rp']) instead of the URL parameter itself. isset() either returns true or false (which count as 1 and 0 respectively), it never returns 2.
    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".
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    8
    Rep Power
    0

    Talking


    Thank you for your suggestion.
    I just make a change on the code it works perfectly
  6. #4
  7. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1046
    You'll want something like this:

    PHP Code:
    <?php

    if (isset($_GET['_rp']))
    {
        if (
    $_GET['_rp'] == 1)
        {
            echo 
    1;
        }
        elseif (
    $_GET['_rp'] == 2)
        {
            echo 
    2;
        }
    }
    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".
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    8
    Rep Power
    0
    i was already did this right before your answer thank you very much..

IMN logo majestic logo threadwatch logo seochat tools logo