這聽起來像你只是想使用GET或POST數據。這裏是基本的樣本。一個人將在form.html上填寫表格並點擊提交。然後您將通過屬性名稱從此表單收集POST數據。在這種情況下,process.php腳本僅打印出「Hello <firstname> <lastname>
」,但也可以根據需要顯示它。
form.html
<form action="process.php" method="post">
<input name="fname" type="text" />
<input name="lname" type="text" />
<input type="submit" />
</form>
process.php
$fname = $_POST['fname'];
$lname = $_POST['lname'];
echo "Hello $fname $lname"
...
如果你想這顯示在同一頁面上的信息,您可以使用AJAX。示例請參閱http://api.jquery.com/jQuery.ajax/。我已經包含了一個如下:
form.html
...
<head>
...
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
// when document is ready do this
$(document).ready(function() {
// listen to when users click on the send button
$('#send-ajax').click(function() {
// get input data
$fname = $('#fname').val();
$lname = $('#lname').val();
// result container
$result = $('#result-ajax');
// create ajax request to process and store
// result in the div container above the form
$.ajax({
url: 'process.php',
type: 'POST',
dataType: 'HTML',
data: {
fname: $fname,
lname: $lname
},
success: function($html) {
$result.html($html);
},
error: function() {
$result.html('<b>Request Failed</b>');
}
});
});
});
</script>
</head>
<body>
<div id="result-ajax"></div>
<input id="fname" />
<input id="lname" />
<button id="send-ajax" value="send">Send</button>
</body>
...
process.php
同上
你可能會想使用類似的file_get_contents' ()'(這裏是該文檔的頁面:http://php.net/manual/en/function.file-get-contents.php)中間有一些例子頁面,應該可以幫助你開始......至少就文件部分而言! – summea 2012-02-24 05:43:41
好的....這是有道理的。我想我的問題是,如果來自Web表單內的文本字段,我將如何使用這些代碼來完成該操作?我認爲我很困惑將它寫入程序語言 – 2012-02-24 05:46:51
你的方法或使用數據庫是否更復雜,但是可以使用簡單的[SQLite數據庫](http:// www。 php.net/manual/en/intro.sqlite.php)?如果您的PHP 5或更高版本,默認情況下啓用SQLite,並且您可以讀取和寫入存儲在磁盤上的單個文件中的sqlite數據庫中的值。 *也許你可以澄清你的表單和數據存儲/檢索的最終目標嗎?* – drew010 2012-02-24 05:48:47