作者iamnodoubt (滑鼠壞了)
看板PHP
標題[請益] 簡易留言板
時間Tue Jun 25 21:52:44 2013
<form method='post' action='test.php'>
<input type='text' name='content'>
<input type='submit'>
<button onclick='<?php clear() ?>'>清除留言</button>
</form>
<?php
function clear()
{
file_put_contents('test.txt',' ');
}
$fh=fopen('test.txt','a+');
fputs($fh,$_POST["content"]."\r\n");
$fh=fopen('test.txt','a+');
$i=1;
while($str=fgets($fh))
{
$str=$i.'.'.$str;
echo $str;
echo '<br>';
$i++;
}
fclose($fh);
?>
兩個問題
1.我多一個清除留言的功能,他就變成只能顯示第一行,每次輸入留言他都會覆蓋過去
感覺應該是指標(不知道他的專有名詞)的問題?
2.清除留言那個按紐,我用
<input type='button' onclick='<?php clear() ?>' value='清除留言'>
看結構應該是正確的,但是卻不能work,麻煩指點一下
感溫
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 175.182.165.146
1F:推 PsMonkey:JavaScript 跟 PHP 的運作時間點搞清楚 06/25 21:55
2F:→ PsMonkey:PHP 可看成字串產生器,js 則是在 browser 上執行那字串 06/25 21:56
3F:推 cychi:你如果要用javascript呼叫php的程式請愛用ajax 06/26 21:37
4F:→ cychi:不然就清除時連結到你的php檔 執行完之後再導回原來的頁面 06/26 21:39
5F:→ cychi:還有如果只是單純要清表單的資料 請用button type="reset" 06/26 21:40