这听起来像你只是想使用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