[請益] 簡易留言板

看板PHP作者 (滑鼠壞了)時間12年前 (2013/06/25 21:52), 編輯推噓2(203)
留言5則, 2人參與, 最新討論串1/1
<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

06/25 21:55, , 1F
JavaScript 跟 PHP 的運作時間點搞清楚
06/25 21:55, 1F

06/25 21:56, , 2F
PHP 可看成字串產生器,js 則是在 browser 上執行那字串
06/25 21:56, 2F

06/26 21:37, , 3F
你如果要用javascript呼叫php的程式請愛用ajax
06/26 21:37, 3F

06/26 21:39, , 4F
不然就清除時連結到你的php檔 執行完之後再導回原來的頁面
06/26 21:39, 4F

06/26 21:40, , 5F
還有如果只是單純要清表單的資料 請用button type="reset"
06/26 21:40, 5F
文章代碼(AID): #1HoQ2kKJ (PHP)
文章代碼(AID): #1HoQ2kKJ (PHP)