brucernorton
asked on
Applying a URL variable to a form element
There is no doubt I am overlooking something very obvious, but I just don't seem to get it. I need to be able to take a url variable and enter it in as the value of a hidden form element. I have tried both javascript and php and I am just missing something. The url variable would be 1234 as in http://www.domain.com/index.php?id=1234, or with javascript http://www.domain.com/index.html?id=1234.
I am trying to get that variable into something like
<input type="hidden" name="ID" value=<?php $_get('id') ?> />
What am I doing wrong?
I am trying to get that variable into something like
<input type="hidden" name="ID" value=<?php $_get('id') ?> />
What am I doing wrong?
A tip for you - $_REQUEST combines many arrays which makes it convenient but unsafe. You can make your own like so
function urlVar( $name ) {
$result = "";
if ( isset( $_GET[$name] ) )
$result = $_GET[$name];
else
if ( isset( $_POST[$name] ) )
$result = $_POST[$name];
return $result;
}
and then just use $myVar = urlVar("aVariable");
You can even escape the data as well and do other stuff like so
http://uk2.php.net/manual/en/function.mysql-real-escape-string.php#81530
function urlVar( $name ) {
$result = "";
if ( isset( $_GET[$name] ) )
$result = $_GET[$name];
else
if ( isset( $_POST[$name] ) )
$result = $_POST[$name];
return $result;
}
and then just use $myVar = urlVar("aVariable");
You can even escape the data as well and do other stuff like so
http://uk2.php.net/manual/en/function.mysql-real-escape-string.php#81530
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you!
<input type="hidden" name="ID" value="<?php echo $_GET['id'] ?>" />