我試圖將密碼或移動無效語句的輸出顯示到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) –