我试图将密码或移动无效语句的输出显示到HTML页面。这里是我的代码:在HTML中调用PHP变量
<?php
session_start();
if(isset($_POST['register'])) {
$phone = ($_POST['tphone']);
$upass = ($_POST['tpassword']);
if ([email protected]_match('/^(?=.*\d{3,})(?=.*[A-Za-z]{5,})[[email protected]#$%]{8,32}$/', $upass)) {
$upass = 'You have enter an invalid password';
}
else if ([email protected]("^[0-9]{3}-[0-9]{7}$", $phone)) {
$mobile = 'Invalid mobile'
}
}
?>
<html>
<body>
<p><?php echo $upass ?>.</p>
<form method="post">
<input type="text" name="tphone" placeholder="First Name" class="form-name" required>
<input type="password" name="tpassword" placeholder="Last Name" class="form-name2" required>
<button type="submit" name = "register" class="btn-register">Register</button>
</form>
</body>
</html>
这里的问题是我应该如何使用PHP
变量在我HTML
像我已经定义$upass
的p
标签内。我还想在单击注册按钮时设置此变量。
现在当我echo $upass
,它显示Undefined variable
时,我没有选择注册按钮。
可能的[如何从HTML或Javascript调用PHP文件]的重复(http://stackoverflow.com/questions/20637944/how-to-call-a-php-file-from-html-or-javascript ) –
'ereg'已被弃用/死亡/消失。你不应该在任何新的代码中使用它,并且使用'@'是PHP的等同物,将你的手指塞进你的耳朵,然后“lalalalalala听不到你”。 –
[PHP:“Notice:Undefined variable”和“Notice:Undefined index”]的可能重复(http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) –