我将把当前输入的数据存储在文本文件中,并从同一文件中获取数据。例如:在form.php中,我输入了表单:
<form name="formData" method="POST" action="landing.php">
<p>NEW DATA:</p>
<input type="text" id="new" name="newdata" />
<p>CURRENT DATA:</p>
<input type="text" id="current" name="current" />
<input type="submit" name="Invia" Value="Invia i dati">
<input type="reset" id="reset" name="Reset" Value="Reset">
</form>
在landing.php中,我是这样的:
<?php
$newdata = $_POST['newdata'];
$current = $_POST['current'];
$file = 'box.xml';
$xml = file_get_contents($file);
$output = str_replace($current, $newdata, $xml);
file_put_contents($file, $output);
?>
如您所见,在提交当前数据和新数据后,xml文件将与新数据一起保存。
这是我的问题:
如何在提交后将$newdata存储在文本文件中,并在form.php中将其显示为$current?
发布于 2015-09-26 20:46:58
在form.php上添加此代码
$file = 'box.xml';
$xml = file_get_contents($file);
在此之后,在当前数据下面添加
<input type="text" id="current" name="current" value="<?php echo $xml; ?>" />
在Landing.php上编辑
<?php
$newdata = $_POST['newdata'];
$file = 'box.xml';
/* there is no need of this code
$current = $_POST['current'];
$xml = file_get_contents($file);
$output = str_replace($current, $newdata, $xml);*/
file_put_contents($file, $newdata);
?>
https://stackoverflow.com/questions/32797209
复制相似问题