Php html表单不显示值
情景: 我在PHP标签中有一个简单的HTML5表单Php html表单不显示值,php,forms,Php,Forms,情景: 我在PHP标签中有一个简单的HTML5表单 <?php echo ' <form method="post" action="index.php"> <input type="email" name="email value="<?php echo $email; ?>"> <input type="passw
<?php
echo '
<form method="post" action="index.php">
<input type="email" name="email value="<?php echo $email; ?>">
<input type="password" name="password">
<button type="submit" name="signin">Sign in</button>
</form>
';
?>
表单显示正确,但我无法获取$email的值,它只显示为原始文本
那么,如何从php标记中的表单回显php变量
最终代码
<?php
echo '<form method="post" action="index.php" class="navbar-form navbar-right">
<input type="email" name="email" placeholder="Email" class="form-control1" value="' . $email . '">
<input type="password" name="password" placeholder="Password" class="form-control">
<button type="submit" name="signin">Sign in</button>
</form>';
?>
尝试关闭表单标记:
<?php
echo '
<form method="post" action="index.php">
<input type="email" name="email"value="<?php echo $email; ?>">
<input type="password" name="password">
<button type="submit" name="signin">Sign in</button>
</form>
';
?>
您需要使用
从字符串中转义出来,并使用
连接,这样您就可以将php变量使用到字符串中
<?php
echo '
<form method="post" action="index.php">
<input type="email" name="email "value="' . $email .'">
<input type="password" name="password">
<button type="submit" name="signin">Sign in</button>
</form>
';
?>
或者像在评论中所说的那样,将html代码放在php结束标记之后
<?php
// Do some code
?>
<form method="post" action="index.php">
<input type="email" name="email "value="<?= $email; ?>">
<input type="password" name="password">
<button type="submit" name="signin">Sign in</button>
</form>
如果要访问echo语句的变量,必须使用双引号。你可以把单引号放在双引号里
$email=”example@gmail.com";
回声“
";
甚至使用
$email=”example@gmail.com";
echo在name和value属性之间放置一个空格,然后将echo放入一个echo中。我认为这是行不通的,只需将html字符串放在php结束标记nice之后,但仍然无法将php echo$电子邮件识别为一个值。我已经有一段时间没有使用php了,只是注意到缺少一个表单标记,所以我想我至少会提供帮助。我似乎还记得使用了$\u POST数组,其中包含数据。不确定这是否有帮助,但可能是值得研究的问题。