Jason Chong
Jason Chong

Reputation: 35

How to pass session variable into a form in PHP?

I currently have this code but it is not display the u_mail

if (isset($_SESSION['u_email'])) {
echo "<form method='POST' action='".setComments($connComment)."'>
<input type='hidden' name='uid' value='$_SESSION['u_email']'>
</form>" } 
getComments($conn)

How do I display it?

I tried testing it by doing:

<?php
 echo $_SESSION['u_email'];
 ?>

And it works completely fine. It is just when I put it in an echo. I actually SHOULD put it in echo. Is there a way in PHP to do that?

Thank you!

Upvotes: 0

Views: 49

Answers (1)

delboy1978uk
delboy1978uk

Reputation: 12365

Just break out from the string and concatenate, like this:

echo "<form method='POST' action='".setComments($connComment)."'>
<input type='hidden' name='uid' value='" . $_SESSION['u_email'] ."'>
</form>";

Upvotes: 4

Related Questions