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!
- 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"] . "";