开发者

Inserting Session variables into a form via PHP

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 开发者_JS百科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


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>


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜