0

how it looksI need to set an input value in a php script

<php
<input value="<?php echo $_SESSION['logged_user']->login; ?>">
?>

As you might understand my does not work

2
  • And what isn't working? What value, if any, is this outputting? Are there any errors in the PHP logs? What is in $_SESSION['logged_user']? Did you start the session on that page? Please elaborate on the problem. Commented Jun 5, 2020 at 11:24
  • yes I did but for some reason it displays what s on the photo Commented Jun 5, 2020 at 11:25

1 Answer 1

1

Your PHP syntax is very confused. While inside of a <?php ?> section you're trying to directly write HTML, and trying to open another <?php ?> section.

Either get rid of the enclosing section:

<input value="<?php echo $_SESSION['logged_user']->login; ?>">

Or keep the enclosing section and use PHP code to output:

<php
echo '<input value="' . $_SESSION['logged_user']->login . '">';
?>
Sign up to request clarification or add additional context in comments.

2 Comments

I highly recommend the first approach over the second approach. It could be shortened even more if you do value="<?= $_SESSION['logged_user']->login ?>"
@GrumpyCrouton: Agreed, though the example given may be contrived and there may be more code involved which could merit the second approach. Both are shown just for completeness.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.