我将如何做到这一点?
<?php
if (isset ($_SESSION['ID'])) {
echo "
<form action = 'updateacct.php' method = 'POST'>
Email:
<input type = 'text' name = 'eml' value = '" . echo $_SESSION['ID'] . "' placeholder = 'Email' size = '30' required/>
</form>
?>
我试图从会话中提取var并将其放在表单值中,并且无法弄清楚如何执行此操作。
答案 0 :(得分:5)
不建议用PHP回显你的整个html ......你可以这样做:
<?php if(isset($_SESSION['ID'])): ?>
<form action='updateacct.php' method='POST'>
Email: <input type='text' name='eml' value='<?php echo $_SESSION['id']; ?>' placeholder='Email' size='30' required/>
</form>
<?php endif; ?>
答案 1 :(得分:2)
不需要第二个回声。你已经回响了。
我拿了你的代码并简化了一下。我使用多个回声来使我们更清楚。
<?php
if (isset($_SESSION['ID'])) {
echo '<form action="updateacct.php" method="POST">';
echo ' Email:';
echo ' <input type="text" name="eml" value="' . $_SESSION['ID'] . '" placeholder="Email" size="30" required />';
echo '</form>';
}
?>
答案 2 :(得分:1)
我会这样:
<?php if (isset ($_SESSION['ID'])) : ?>
<form action = 'updateacct.php' method = 'POST'>
Email:
<input type = 'text' name = 'eml' value = '<?= $_SESSION['ID'] ?>' placeholder = 'Email' size = '30' required/>
</form>
<?php endif; ?>
答案 3 :(得分:0)
你可以说:
<?php
if (isset ($_SESSION['ID'])) {
?>
// HTML goes here
<?php
}
?>