[英]HTML Forms to display comments
我正在HTML網頁上創建表單,以便訪問者可以添加有關我的頁面的評論。 這包括不同類型的表格,我正在努力為單選按鈕添加if else語句。 我的html代碼被發布了打擊,然后鏈接到它的php被發布了。 請幫忙!!!
<html>
<form action="process_comment.php" method="post">
Name:
<input type="text" name="username" value=""/>
<br>
</form>
<form action="process_comment.php" method="post" >
Do you like this page?
<input type = "radio" name = "like" value = "0"> Yes
<input type = "radio" name = "like" value = "1"> No
<br>
<input type="submit" value ="go" /><br>
</form>
</html>
<?php
$userName=$_POST["username"];
echo "Hello <b>$userName</b>!<br>";
?>
<?php
$like = $_POST["like"];
if($like = "post") {
echo "I am happy that you <b>like</b> this page :)";
} else {
echo "I am sorry that you <b>do not like</b> my page :(";
}
?>
您正在使用兩種形式,一種操作嘗試下面的代碼,並將兩種形式合並為一種。
<html>
<form action="process_comment.php" method="post">
Name:
<input type="text" name="username" value=""/>
<br>
Do you like this page?
<input type = "radio" name = "like" value = "0"> Yes
<input type = "radio" name = "like" value = "1"> No
<br>
<input type="submit" name="submit" value ="go" /><br>
</form>
</html>
並在process_comment.php中
<?php
if(isset($_POST['submit'])
{
$userName=$_POST["username"];
echo "Hello <b>$userName</b>!<br>";
$like = $_POST["like"];
if($like) {
echo "I am happy that you <b>like</b> this page :)";
}
else {
echo "I am sorry that you <b>do not like</b> my page :(";
}
}
?>
如果value是1或0,則可以在if條件中使用變量,因為它可以是true或false。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.