我試圖製作一個表單,迴應出無論用戶輸入到'名稱'字段,但是,我不明白爲什麼當我添加if
語句時,代碼中沒有任何內容顯示出來。當我添加if語句到我的PHP代碼時,怎麼會出現什麼?
這裏是我的index.php
代碼:
<?
if (empty($_POST['name'])) {
echo "Hello world!";
} else {
echo "Hello $_POST['name']";
}
?>
<html>
<head>
<?php include 'header.php'; ?>
</head>
<body>
<form action="index.php" method="post">
<p>Name: <input type="text" name="name"></p>
<input type="submit" name="submit" value="Go">
</form>
</body>
<footer>
<?php include 'footer.php'; ?>
</footer>
</html>
也許嘗試改變從'<'第一行'
Quill
你也不應該直接把'$ _POST ['name']'放入類似的字符串中。使用字符串連接或類似的東西。 – Quill
如果你想引用$ _POST [''],把{}圍繞$ _POST [] - 即:'「你好{$ _POST ['name']}」' – RamRaider