html: input type 改為 password。
<form method="post" action="index.php">
<p>
<label for ="user">帳號:</label>
<input type="text" name="user">
</p>
<p>
<label for ="password">密碼:</label>
<input type="password" name="password">
</p>
<input type="submit" name="send" value="送出">
</form>
php: 檢查是否為空值,用empty()
函式。
<?php
$user = $_POST["user"];
$password = $_POST["password"];
if(empty($user)){
echo "請輸入帳號!";
}else
if(isset($_POST["send"])){
echo "帳號:"."$user"."</br>";
echo "密碼:"."$password"."</br>";
}
?>
輸出: