3 quick questions:
I want to create one page "view_build.php" which, when opened, takes a variable from the URL contained within it, and displays unique information for that 'build'. For example
<a href="view_build.php?buildname=$row[0]">$row[0]</a>
The above is a link to a page called view_build.php?buildname=VARIABLE
Does the .php file contain the variable in a $_GET array, JUST from me including a variable name in the html link?
And if so, is it okay if there are spaces in it? For example:
view_build.php?buildname=Dual Zoren
Lastly, how do I include more than one variable in the URL? What is the syntax?
Thanks so much! Regards.
Does the .php file contain the variable in a $_GET array, JUST from me including a variable name in the html link?
Yes. To elaborate, if you call view_build.php
via an HTTP request with the URL query parameters foo=bar
, then within that script, you can access $_GET['foo']
which will have the value bar
.
is it okay if there are spaces in it?
No, they should be URL encoded. See http://php.net/manual/function.urlencode.php
For example
<a href="view_build.php?buildname=<?= urlencode($row[0]) ?>"><?= htmlspecialchars($row[0]) ?></a>
Lastly, how do I include more than one variable in the URL? What is the syntax?
URL query parameters are separated by the &
character, eg
view_build.php?buildname=Dual+Zoren&foo=1&bar=2