我想你想存儲的數量,因此它總是顯示並可以對其進行更新,當你的時髦雞下蛋。前面的答案將允許您增加數字,但只有在打開瀏覽器時纔會增加。
我認爲最好的方法是使用PHP。
因此,首先你希望你的頁面是.php,可以說admin/loggedin.php。
你想創建一個名爲eggs.txt同一目錄下一個空白文件,與0755
然後你希望你的形式看起來像這樣
<form method="POST" action="loggedin.php">
<input type="text" name="num" value="0"/>
<input type="submit" value="Chicken came first" name="eggs">
</form>
權限爲了解釋方法/動作:
method
是要如何將數據發送到
action
page。
選項是$_POST和$_GET,我不認爲在這裏過多的細節將有所幫助。
action =是告訴表單要發送這些數據的頁面,在這種情況下,我們選擇將它發送到表單所在的頁面(loggedin.php)。
所以,現在,一旦您提交表單,我們將有一個$ _POST ['num']可用於我們,其中包含您輸入到表單輸入字段中的數字。
爲了得到這個,你要在你的頁面的頂部添加:EDIT(已經改變了下面的代碼段 - file_put_contents應該得到的,如果($ _ POST [「蛋」]){
<?php
//this checks to see if the form was submitted by checking 'eggs' is set.
if($_POST['eggs']) {
// create a nicer variable for our egg number, it deserves a nice name.
$egg = $_POST['num'];
//this will put the new number of eggs in our eggs.txt file
file_put_contents('eggs.txt',$egg);
}
?>
內
file_put_contents()寫入你希望能夠得到您的頁面上顯示的文件號文件
下一步要做到這一點:
<div class="my_egg_count">
<?php echo file_get_contents('eggs.txt'); ?>
</div>
file_get_contents()讀取文件,從服務器到客戶端回顯「echo's」。
讓我知道如果你有這個問題,你不想最終與你的臉蛋。
編輯::試試這個
if(is_writeable('eggs.txt')) {
if(file_put_contents('eggs.txt',$egg)) {
echo 'File Updated';
}else {
echo 'Error Updating File';
}
}else {
echo "Error: File Isn't Writeable [possibly named incorrectly, isn't in the correct location, or wrong permissions]";
}
你想要的數據持久化?如果你希望它堅持下來,放入數據庫並從中讀取實際值。然後你可以有一個運行腳本的按鈕來更新數據庫中的值。 – Tdelang
我想你需要的是一些服務器端編程,否則頁面將無法存儲當前的蛋數。 –
Sever端編程沒有問題,我物理上擁有服務器,它是後院的一個覆盆子pi。 – Dragongeek