• Hi,

    I was wondering if anyone would be able to help with a problem that I am having with a WordPress site that I am creating.

    On the homepage, I have a form that puts variables into the url and goes to a page. It looks a bit like this: https://www.example.com/page/?name=will

    My question is, how do I get the value of ‘name’ and then echo/display that on my page?

    Thanks a lot in advance.

Viewing 10 replies - 1 through 10 (of 10 total)
  • jessy

    (@jessy-marco)

    Put the code in the same place as the form is:

    echo $name = $_POST['name'];

    If you’re passing the values via the URL you need to use GET:

    $name = $_GET ['name'];

    jessy

    (@jessy-marco)

    $name = $_POST['name']; method is more secure.

    No it’s not. You can change both POST and GET values pretty easily.

    The big issue is that $_POST doesn’t return values from the URL so you have to use $_GET for that.

    jessy

    (@jessy-marco)

    Yes, I fully agree with you, but it is better to have hidden variables and url looks clean.

    Yes, but that’s not what the OP asked for. ??

    There are a lot of cases where you should use a form to submit values but there’s also a lot where passing by the url is easier and no more of a risk.

    jessy

    (@jessy-marco)

    catacaustic Always give to people more and you always get a lot more. It depends on you what you want. I want more.

    But what does banfw001 want? We haven’t heard back from them yet, and I’ll wait for that one now. My main point was that when they asked about gettign the value from the URL you gave them an example with $_POST which is incorrect. I was only trying to rectify that so that there’d be a lot less confusion then there would be if they tried using $_POST and couldn’t get a value from the URL.

    jessy

    (@jessy-marco)

    catacaustic And I replied to you very soon this “Yes, I fully agree with you …” Read above.

    Thread Starter banfw001

    (@banfw001)

    Thanks for all of your replies. catacaustic solved my problem. It is not secure data that is being passed.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Passing Variables in URL’ is closed to new replies.