【发布时间】:2025-12-03 02:55:02
【问题描述】:
我正在尝试将密码或移动无效语句的输出显示到 HTML 页面。这是我的代码:
<?php
session_start();
if(isset($_POST['register'])) {
$phone = ($_POST['tphone']);
$upass = ($_POST['tpassword']);
if (!@preg_match('/^(?=.*\d{3,})(?=.*[A-Za-z]{5,})[0-9A-Za-z!@#$%]{8,32}$/', $upass)) {
$upass = 'You have enter an invalid password';
}
else if ( !@ereg( "^[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>
这里的问题是我应该如何在HTML 中使用PHP 变量,就像我在p 标签内定义的$upass 一样。我也想在点击注册按钮时设置这个变量。
现在当我echo $upass时,当我没有选择注册按钮时它显示Undefined variable。
【问题讨论】:
-
ereg已弃用/死亡/消失。你不应该在任何新代码中使用它,使用@相当于把你的手指塞进你的耳朵然后“lalalalalala 听不到你”。
标签: javascript php html post