Forum Moderators: coopster

Message Too Old, No Replies

How to embed a variable in a php echoed form

         

s9901470

2:09 pm on Nov 21, 2005 (gmt 0)

10+ Year Member



Hi

I'm trying to embed a hidden variable 'username' in a form, but the form is generated by php echo.

This isn't working at the moment, could anyone tell me how to format the $_SESSION["username"] bit please?

At the moment it prints " /> and I lose the variable.

<?php
echo '<form action="formt.php" method="post">
<input type="hidden" name="uname" value="$_SESSION["username"]" />
<input type="submit" label="submit"></form>';
?>

Thanks

Anyango

2:40 pm on Nov 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<?php
echo '<form action="formt.php" method="post">
<input type="hidden" name="uname" value="'.$_SESSION["username"].'"><input type="submit" label="submit"></form>';
?>

;)

PHP variables arent parsed if they are done echo within single quotes, you dont need to enclose them however you can use doulbe quotes for that

phparion

3:20 pm on Nov 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



use Double Quotes where you have used single and Single Quotes instead of double quotes in your code it will be ok