Web Hosting Talk







View Full Version : Send PHP Variable in HTML Form


Cyberoonie
08-08-2007, 05:21 PM
Hi,

I've been playing around trying to get a php variable to work as a value in a HTML form.

What I have is the form on a page called usercomment.php?cmd=viewrecord&id=xx where xx is a number for example 10.

I want the HTML form to be able to send the id via a $_GET['id'] as a value in a hidden field. The code I have tired is:

<form action="postcomment.php" method="post" enctype="multipart/form-data" name="internalcomment">
<input name="recordid" type="hidden" value="<?php $_GET[id];?>">

It doesnt work as it doesnt send the id number. If I physically write the value 10 in the entire script works fine, I just cant get it to send a variable id value.

Thanks

berumelu
08-08-2007, 07:03 PM
There is missing some characters.
Try this:

value="<?php $_GET[‘id’];?>"

Regards,

Luis Berumen

Engelmacher
08-08-2007, 07:19 PM
Try an echo

Cyberoonie
08-08-2007, 07:26 PM
My god, why didnt I think of trying it with an echo in there.

Thanks for your help both of you, i've put the ' back into the brackets and added echo.

Thanks!

Mc NaN
08-09-2007, 06:42 AM
You can do it this way too:

value="<?=$_GET["id"];?>"