如果點擊其中一個按鈕,我該如何實現按鈕點擊php?我試圖做的是,如果點擊了透過按鈕下面的PHP腳本顯示它寫入一個文件,如果查看評論正在熱播節目評論需要Php按鈕動作事件
<html>
<body>
<form action="http://localhost/class/assignment10.php" method="post">
User Name: <input type="text" name="uname"><br>
User Comments: <textarea type ="text" name="tcomment"></textarea><br>
<input type="submit" value="Submit Comments"/>
<input type="submit" value="View Comments"/>
</form>
</body>
</html>
我有兩個表單按鈕IF提交意見是clickedthe PHP代碼應將用戶名和註釋寫入文本文件(使用fputs函數寫入文件,並且在每個名稱和每個註釋之後插入換行符)。如果用戶點擊'查看所有評論'按鈕,php代碼應該顯示所有用戶及其相應的評論(使用fgets功能)
<html>
<head>
<title>PHPLesson10</title>
</head>
<body>
<?php
// Collect user name and add a line break at the end.
$customer = $_POST['uname']."\n";
// Collect comment and add a line break.
$comments = $_POST['tcomment']."\n";
$file = fopen("C:/data/feedback.txt", "a");
If ($file) // if the file open successfully
{
// Write the variables to the file.
fputs($file, $customer);
fputs($file, $comments);
fclose($file);
}
Else
{
Echo "Please try again.";
}
?>
</body>
</html>
<?php
// Open the file feedback for reading
$file = fopen("C:/data/feedback.txt", "r");
// While the end of the file has NOT reached
While (!feof($file))
{
// Print one line of file
Echo fgets($file);
Echo "<br />";
}
// close the connection
fclose($file);
?>
PHP執行服務器端。你將不得不看看JavaScrpt和Ajax。即使如此,我也不確定你能寫信給用戶的機器。 – durbnpoisn
我正在使用xampp appache模塊 –