這是我的代碼:PHP:isset修改HTML元素
<?php
$printhename = $_POST['username3'];
if(isset($_POST['username3']) && $printhename == "Carlos"){
echo "<h1 class='title123'>Hello $printhename </h1>";
}
else {
echo "<h1 class='title123'>You don't belong here!</h1>";
}
?>
我想要做的是,如果「USERNAME3」沒有設置,消息「你不屬於這裏顯示」。否則,如果名稱已設置並且是卡洛斯,則顯示其他消息。無論輸入的名稱如何,我都必須以錯誤的方式執行此操作,因爲它總是打印「Hello $ printhename」。
我希望有人對此有所瞭解。我是PHP新手。
如果有幫助,這是我的HTML代碼:
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<div class="centerlogin">
<form class="formlogin" name="login" method="POST" action="testing.php">
<input type="text" placeholder="username" NAME="username3">
<input type="submit" name="login_submit" value="login">
</form>
</div>
</div>
'$ printhename = $ _POST ['username3'];'在錯誤的位置。 '&& $ printhename'使用POST數組。 –
您的第一個變量也未定義,並使用POST數組檢查是否等於「Carlos」。 –
順便說一句,你刪除了你的評論我回復;-)只是說。你問我在哪裏放,但正在忙着寫我的答案。保持你接受的答案,我完全贊成。 –