Pass parameter in url php

I have a form and a PHP function:




  

But when I click to submit I get nothing.

How can I pass variable a in URL [without any inputs] and why this method doesn't work?

Test!

  1. Use a form with GET, and have the field as hidden.

    
    

You are mixing both methods, and the contents of the GET form, override your action.

answered Jan 19, 2017 at 15:54

ArisAris

4,3481 gold badge38 silver badges36 bronze badges

Try this, instead of:

if[isset[$_GET['sub']]] {

use:

if[isset[$_GET["sub"]]}

Akber Iqbal

14k12 gold badges47 silver badges63 bronze badges

answered Dec 20, 2019 at 1:02

URL syntax

in this example we have this url

www.htmlexample.org/phpexample.php

Before passing a variable using the url first add a '?' to the end of the normal url

www.htmlexample.org/phpexample.php?

after the ? add the name of the variable

www.htmlexample.org/phpexample.php?varName

put an "=" then add the value assigned to the variable name

www.htmlexample.org/phpexample.php?varName=value

to pass more then one variable repeat above but only have '?' before the first one and a '&' in between each new variable

www.htmlexample.org/phpexample.php?varName=value&othervarName=othervalue

Getting the variables

To get the variable values from the url use the $_GET method

for example to get the value of the variable varName use

$_GET["varName"]

use $_GET the same as any other method

Example

this is an example of passing a string variable tom and int variable 22 to the php script

then using the 2 variables in the webpage

www.htmlexample.org/phpexample.php?name=tom&age=22

echo "Name " . $_GET["name"] . "";

echo"Age " . $_GET["age"] . "";

How can I pass POST parameters in a URL?

You could use a button instead of an anchor and just style the button to look like a link. That way you could have your values in hidden fields inside the same form to be sent via POST. In addition to what Ben said, you can also let the link be a dummy and have it execute a javascript that submits a hidden form.

What is $_ GET in PHP?

PHP $_GET is a PHP super global variable which is used to collect form data after submitting an HTML form with method="get". $_GET can also collect data sent in the URL. Assume we have an HTML page that contains a hyperlink with parameters:

How do I pass a URL in a query string?

To pass in parameter values, simply append them to the query string at the end of the base URL. In the above example, the view parameter script name is viewParameter1.

How can I get params in PHP?

The parameters from a URL string can be retrieved in PHP using parse_url[] and parse_str[] functions. Note: Page URL and the parameters are separated by the ? character. parse_url[] Function: The parse_url[] function is used to return the components of a URL by parsing it.

Chủ Đề