views:

286

answers:

2

I am trying to insert a Session Variable $_SESSION['MM_loginName'] into a table via a form.

I know the Session Variable works on the new page by using:

<?php
 echo "MM_loginName = {$_SESSION['MM_loginName']} <br>\n";
?>

I have read that this might work (if register globals is off):

<input type="hidden" name="loginName" value="<?php echo $_SESSION["MM_loginName"]; ?>" />

but it doesn't, because I think register globals has been DEPRECATED.

This is supposed to work:

<input type="hidden" name="username" value="<?php echo "$myusername"; ?>" />

but i don't know how to rewrite the code to "$loginName"

Help,

Here is my table/form structure:

<tr>
   <td width="99"></td>
   <td width="391"><input type="hidden" name="loginName" id="loginName" value= "????/></td>
</tr>

Thanks Michael

+1  A: 

I think your first one isn't working because references to array variable values within strings aren't evaluated within echo statements. Assuming that you want to put the username, which is stored in the session, into the value field of your form, I would do something like:

<tr>
   <td width="99"></td>
   <td width="391"><input type="hidden" name="loginName" id="loginName" value= "<?php echo $_SESSION['MM_loginName']; ?>" /></td>
</tr>
pr1001
Winnner Winner Chicken Dinner!!!! Thanks that worked perfectly...Thanks a bazillion..michael
Michael Robinson
Hehe, you're welcome.
pr1001
A: 

If the first code fragment works, there is no logical reason for the second not to work. They are exactly the same thing from a PHP perspective.

You do have to register the session before any calls to the session global, see http://php.net/manual/en/function.session-register.php

Devin Ceartas
Sorry, they both don't work, Do you know how to turn the $_SESSION["MM_loginName"] into $myloginName ?
Michael Robinson
`$myloginName = $_SESSION["MM_loginName"];`There's nothing special going on...
pr1001