提交后保留数据

时间:2018-07-31 14:19:20

标签: php html variables post

我有一个index.html和process.php

Index.html

<html>   
<head>
 <title>Test Page</title>
</head>   
<body>   
    <h2>Data Collection</h2><p>
    <form action="process.php" method="post">  
        <table>
            <tr>
                <td>Name:</td>
                <td><input type="text" name="Name"/></td>
            </tr>   
            <tr>
                <td>Age:</td>
                <td><input type="text" name="Age"/></td>
            </tr>   
            <tr>
                <td colspan="2" align="center">
                <input type="submit"/>
                </td>
            </tr>
        </table>
    </form>
</body>
</html>

Process.php

<?php   
    print "Your name is ". $Name;   
    print "<br />";   
    print "You are ". $Age . " years old";   
    print "<br />";   $old = 25 + $Age;
    print "In 25 years you will be " . $old . " years old";   
?>

我想基于多个提交构建表格或表格。因此,进程文件应生成如下内容:

name, age
Jan, 45
Michael, 43
Esther, 23

我不会使用文本文件或数据库。我读了一些有关会话变量的信息...

3 个答案:

答案 0 :(得分:0)

这不起作用:

(SUM([Previous Open Claims])-SUM([Current Open Claims]))/SUM([Previous Open Claims])

我想生成一个提交名称列表...

答案 1 :(得分:0)

会话不是持久性的,因此它们不适合您的用例。如果您确实不想存储数据,则必须使用数据库或文件。

这可能是基于文件的方法,您的process.php将如下所示:

$data = implode(',', $_POST);
file_put_contents('storage.txt', $data . PHP_EOL, FILE_APPEND);

答案 2 :(得分:0)

此代码在php文件中工作。

<form method="POST" action="">
    <input type="text" name="Voornaam" value=""></input>
    <input type="text" name="Achternaam" value=""></input>
	<input type="text" name="Telefoon" value=""></input>
    <input type="text" name="Email" value=""></input>
    <input type="submit" name="Verzenden"></input>
</form>




<?php

	session_start();
	
	if(isset($_POST['Voornaam']) && $_POST['Voornaam']!='') {

   	$_SESSION['Voornaam'] = $_SESSION['Voornaam'] . $_POST['Voornaam']; 
   	$_SESSION['Achternaam'] = $_SESSION['Achternaam'] . $_POST['Achternaam']; 
   	$_SESSION['Telefoon'] = $_SESSION['Telefoon'] . $_POST['Telefoon']; 
   	$_SESSION['Email'] = $_SESSION['Email'] . $_POST['Email']; 
   	
   	$_SESSION['Rij'] = 	$_SESSION['Rij'] . '<tr>' . PHP_EOL;
	$_SESSION['Rij'] .= '<td>' . $_POST['Voornaam'] . '</td>' . PHP_EOL;
	$_SESSION['Rij'] .= '<td>' . $_POST['Achternaam'] . '</td>' . PHP_EOL;
	$_SESSION['Rij'] .= '<td>' . $_POST['Telefoon'] . '</td>' . PHP_EOL;
	$_SESSION['Rij'] .= '<td>' . $_POST['Email'] . '</td>' . PHP_EOL;
	$_SESSION['Rij'] .= '</tr>';	


	echo '<table border="1">';
	echo '<tr>';
	echo '<th>Voornaam</th>';
	echo '<th>Achternaam</th>';
	echo '<th>Telefoon</th>';
	echo '<th>Email</th>';
	echo '</tr>';
	echo $_SESSION['Rij'];
	echo '</table>';
	
	}

	
?>