WordPress.org

Support

Support » Plugins and Hacks » Insert PHP » [Resolved] Use $_GET

[Resolved] Use $_GET

Viewing 14 replies - 1 through 14 (of 14 total)
  • Yes it should be. I have a script running now that implements $_GET and never had any issues. 🙂

    It is not working for me, I have this URL for example and this php code below:

    URL: http://www.shorexiceland.is/thank-you/?booking_id=QYFA-250314&total=178.00&date=2014-06-02&sku=thegoldencir:2

    Your booking ID:

    [insert_php] echo $_GET[booking_id]; [/insert_php]
    Total amount of the booking:

    [insert_php] echo $_GET[‘total’]; [/insert_php]

    etc. but nothing is visible on the page.

    Plugin Author WillBontrager

    @willbontrager

    GretarMagg, try

    echo $_SERVER['QUERY_STRING'];

    It will tell you what the PHP script actually sees as the URL parameter (if anything).

    Put the key in quotes or apostrophes, like

    echo $_GET['booking_id'];

    Will

    I have my key quotes in apostrophes. But still nothing appears on my page…

    echo $_SERVER[‘booking_id’];

    is not working either. Below is my complete code:

    Your booking ID: 
    
    [insert_php] echo $_SERVER['booking_id']; [/insert_php]
    
    Total amount of the booking:  
    
    [insert_php] echo $_SERVER['total']; [/insert_php]
    
    The date of your tour/tours:  
    
    [insert_php] echo $_GET['date']; [/insert_php]
    
    Item SKU and order quantity in the booking:
    
    [insert_php] echo $_GET['sku']; [/insert_php]
    
    [insert_php] $string = "PHP code to test"; echo $string; [/insert_php]

    As you can see at the bottom I’m checking if the string PHP code to test is written out and that works out fine on the page.

    Please note that I have tried $_SERVER and $_GET

    Plugin Author WillBontrager

    @willbontrager

    GretarMagg, Try this, just to see what $_GET variables area actually available on the page:

    ‘[insert_php] echo $_SERVER[‘QUERY_STRING’]; [/insert_php]`

    Will

    Ok, I did that and this is what appears on the page

    booking_id=QYFA-250314&total=178.00&date=2014-06-02&sku=thegoldencir:2

    Plugin Author WillBontrager

    @willbontrager

    OK, looks like the values are getting to the page. Don’t know why it’s not working. Maybe $_GET is initialized somewhere before the Insert PHP code block.

    Let’s see what this will do:

    [insert_php]
    echo '<pre>';
    print_r($_GET);
    echo '</pre>';
    [/insert_php]

    That should print out all $_GET keys and values available at that point on the page.

    Will

    YES ! That writes out

    Array
    (
    [booking_id] => QYFA-250314
    [total] => 178.00
    [date] => 2014-06-02
    [sku] => thegoldencir:2
    )
    

    on the page.

    Plugin Author WillBontrager

    @willbontrager

    OK, the $_GET array is available and has values.

    This should work:

    [insert_php]
    echo('Booking ID: ' . $_GET['booking_id'] . '<br>');
    echo('Total: ' . $_GET['total'] . '<br>');
    echo('Date: ' . $_GET['date'] . '<br>');
    echo('SKU: ' . $_GET['sku']);
    [insert_php]

    Don’t know why it didn’t, before.

    Will

    No, strangely enough this does not work… I even tried to set up this echo

     stuff before but that did not change anything.
    
    [insert_php]
    
    echo '
    '; echo('Booking ID: ' . $_GET['booking_id'] . ''); echo '

    ‘;

    echo(‘Total: ‘ . $_GET[‘total’] . ‘
    ‘);

    echo(‘Date: ‘ . $_GET[‘date’] . ‘
    ‘);

    echo(‘SKU: ‘ . $_GET[‘sku’]);

    [/insert_php]

    Plugin Author WillBontrager

    @willbontrager

    Yes, you’re right. It is strange. $_SERVER[‘QUERY_STRING’] is available. The $_GET array is available. Yet, values in individual $_GET keys can’t be echo-ed.

    The reason may be another plugin. Or something else on the page. Or a customization done with a template. Or something weird being typed into the Insert PHP code block, maybe a word processor formatting code.

    You could try creating your own variables by parsing the $_SERVER[‘QUERY_STRING’] value. If you do that, the variables will need to be echo-ed in the same Insert PHP code block where they are created. (Generally, Insert PHP code blocks don’t talk to each other.)

    Unfortunately, I’m unable to go further with this without hands-on testing. Insert PHP works fine for echoing $_GET key values in other installations. Therefore, the reason is most likely to be something about the WordPress installation or the way the Insert PHP code block is entered into the post or page.

    Sorry I can’t go further with this.

    Will

    Ok, no problem, I can maby try to write out the values in the array with the php code that worked.

    Well this is strange, when I do this, it works like a charm:

    Your Booking ID : [insert_php] echo ''; print_r($_GET['booking_id']); echo ''; [/insert_php]
    
    Total amount of the booking : [insert_php] echo ''; print_r($_GET['total']); echo ''; [/insert_php]
    
    The date of your tour/tours : [insert_php] echo ''; print_r($_GET['date']); echo ''; [/insert_php]
    
    Item SKU and order quantity in the booking (quantity is after the colon) : [insert_php] echo ''; print_r($_GET['sku']); echo ''; [/insert_php]
    Plugin Author WillBontrager

    @willbontrager

    Ah, I didn’t think about using print_r($_GET['booking_id'])

    Good thought, that, GretarMagg.

    Evidently, whatever is suppressing the echo of individual $_GET key values is somehow bypassed by using print_r() instead.

    I’m glad you found a workaround.

    Will

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘[Resolved] Use $_GET’ is closed to new replies.
Skip to toolbar