The result entered doesn't show after I submit form. It shows on the next submit and so on.
Any ideas would be very much appreciated, thanks.
Code: Select all
[color=#0000FF]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Names Array</title>
<style>
td{ border: 1px solid black;}
table{ margin: 20px; margin-right: auto; margin-left: auto;}
.missing{ background-color: #99CC99; border-collapse: collapse;}
</style>
</head>
<body>
<?php
$loop = array();
$names = array(array());
$i = 0;
$loop = unserialize(urldecode($_POST['loop']));
$names = unserialize(urldecode($_POST['names']));
if(isset($_POST['clear'])){
$loop = array();
$names = array();
}
if(!empty($loop)){
echo '<table>';
foreach($loop as $v){
$i++;
}
for($d = 0; $d < $i; $d++){
$x = 0;
$y = 1;
echo '<tr><td>' . $names[$d][$x] . ' ' . $names[$d][$y] . '</td></tr>';
}
echo '</table>';
}
echo '<form action="" method="post"><table>
<tr><td>First</td><td><input type="text" name="first" /></td></tr>
<tr><td>Last</td><td><input type="text" name="last" /></td></tr>
<tr><td></td><td>
<input type="submit" name="input" value="Input" />
<input type="submit" name="clear" value="Clear" />
</td></tr>
</table>';
if(isset($_POST['input'])){
$x = 0;
$y = 1;
$names[$i][$x] = $_POST['first'];
$names[$i][$y] = $_POST['last'];
$i++;
$loop[] = $i;
}
$s_loop = urlencode(serialize($loop));
$s_names = urlencode(serialize($names));
echo '<input type="hidden" name="loop" value="' . $s_loop . '" />
<input type="hidden" name="names" value="' . $s_names . '" />
</form>';
?>
</body>
</html>[/color]