WordPress.org

Ready to get started?Download WordPress

Forums

Insert PHP
[resolved] Use $_GET (15 posts)

  1. GretarMagg
    Member
    Posted 5 months ago #

    Hello

    Is it possible to write out the variables that are in the custom URL I am posting back to my WP page with this plugin ?

    For example [insert_php] echo $_GET['total']; [/insert_php]

    https://wordpress.org/plugins/insert-php/

  2. Smaandar
    Member
    Posted 5 months ago #

    Yes it should be. I have a script running now that implements $_GET and never had any issues. :)

  3. GretarMagg
    Member
    Posted 5 months ago #

    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.

  4. WillBontrager
    Member
    Plugin Author

    Posted 5 months ago #

    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

  5. GretarMagg
    Member
    Posted 5 months ago #

    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

  6. WillBontrager
    Member
    Plugin Author

    Posted 5 months ago #

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

    '[insert_php] echo $_SERVER['QUERY_STRING']; [/insert_php]`

    Will

  7. GretarMagg
    Member
    Posted 5 months ago #

    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

  8. WillBontrager
    Member
    Plugin Author

    Posted 5 months ago #

    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

  9. GretarMagg
    Member
    Posted 5 months ago #

    YES ! That writes out

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

    on the page.

  10. WillBontrager
    Member
    Plugin Author

    Posted 5 months ago #

    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

  11. GretarMagg
    Member
    Posted 5 months ago #

    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]

  12. WillBontrager
    Member
    Plugin Author

    Posted 5 months ago #

    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

  13. GretarMagg
    Member
    Posted 5 months ago #

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

  14. GretarMagg
    Member
    Posted 5 months ago #

    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]
  15. WillBontrager
    Member
    Plugin Author

    Posted 5 months ago #

    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

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.