PHP Form: After getting results adding a new table row when entering new information.
- by Chris
Hello,
Although probarly quite simple, i cannot seem to find the following.
The form takes certain data, and then represents the data in a table.
Next step i click the hyperlink that takes me back to the form.
Now my question is how exactly do i make it possible when filling in the same form again so both results are displayed in the same table?
Then filling in a other form with data adds another row and so on.
Regards.
The code below (pardon me that it is not english).
<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-Strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>ExpoFormulier</title>
<body>
<?php
if (!empty($_POST))
{
$standnaam = $_POST["standnaam"];
$oppervlakte = $_POST["oppervlakte"];
//value in the form van checkboxes op 1 zetten!
$verdieping = isset($_POST["verdieping"]) ? $_POST["verdieping"] : 0; //if checkbox checked value 1 anders 0
$telefoon = isset($_POST["telefoon"]) ? $_POST["telefoon"] : 0;
$netwerk = isset($_POST["netwerk"]) ? $_POST["netwerk"] : 0;
if (is_numeric($oppervlakte))
{
$_SESSION["standnaam"]=$standnaam;
$_SESSION["oppervlakte"]=$oppervlakte;
$_SESSION["verdieping"]=$verdieping;
$_SESSION["telefoon"]=$telefoon;
$_SESSION["netwerk"]=$netwerk;
header("Location:ExpoOverzicht.php"); //verzenden naar ExpoOverzicht.php dmv header
}
else
{
echo "<h1>Foute gegevens, Opnieuw invullen a.u.b</h1>";
}
}
?>
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post" id="form1">
<h1>Vul de gegevens in</h1>
<table>
<tr>
<td>Standnaam:</td>
<td><input type="text" name="standnaam" size="18"/></td>
</tr>
<tr>
<td>Oppervlakte (in m^2):</td>
<td><input type="text" name="oppervlakte" size="6"/></td>
</tr>
<tr>
<td>Verdieping:</td>
<td><input type="checkbox" name="verdieping" value="1"/></td>
<!--value op 1 zetten voor checkbox! indien checked is value 1 -->
</tr>
<tr>
<td>Telefoon:</td>
<td><input type="checkbox" name="telefoon" value="1"/></td>
</tr>
<tr>
<td>Netwerk:</td>
<td><input type="checkbox" name="netwerk" value="1"/></td>
</tr>
<tr>
<td><input type="submit" name="verzenden" value="Verzenden"/></td>
</tr>
</table>
</form>
Second File:
<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-Strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>ExpoOverzicht</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link href="StyleSheetExpo.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Overzicht van de ingegeven standen in deze sessie</h1>
<?php
$standnaam = $_SESSION["standnaam"];
$oppervlakte = $_SESSION["oppervlakte"];
$verdieping = $_SESSION["verdieping"];
$telefoon = $_SESSION["telefoon"];
$netwerk = $_SESSION["netwerk"];
$result1 = 0; //telkens declaren anders fout "undefined variable"
$result2 = 0;
$result3 = 0;
$prijsCom = 0;
$prijsVerdieping = 0;
for ($i=1; $i <= $oppervlakte; $i++)
{
if($i <= 10)
{
$tarief1 = 1 * 100;
$result1 += $tarief1;
}
if($i > 10 && $i <= 30)
{
$tarief2 = 1 * 90;
$result2 += $tarief2;
}
if($i > 30)
{
$tarief3 = 1 * 80;
$result3 += $tarief3;
}
}
$prijsOpp = $result1 + $result2 + $result3;
if($verdieping == 1)
{
$prijsVerdieping = $oppervlakte * 120;
}
if(($telefoon == 1) || ($netwerk == 1)) // eerst deze OR conditie of anders gebruikt de code alleen nog maar 20
{
$prijsCom = 20;
}
if(($telefoon == 1) && ($netwerk == 1))
{
$prijsCom = 30;
}
$totalePrijs = $prijsOpp + $prijsVerdieping + $prijsCom;
echo "<table class=\"tableExpo\">";
echo "<th>Standnaam</th>";
echo "<th>Oppervlakte</th>";
echo "<th>Verdieping</th>";
echo "<th>Telefoon</th>";
echo "<th>Netwerk</th>";
echo "<th>Totale prijs</th>";
echo "<tr>";
echo "<td>".$standnaam."</td>";
echo "<td>".$oppervlakte."</td>";
echo "<td>".$verdieping."</td>";
echo "<td>".$telefoon."</td>";
echo "<td>".$netwerk."</td>";
echo "<td>".$totalePrijs."</td>";
echo "</tr>";
echo "</table>";
?>
<a href="ExpoFormulier.php">Terug naar het formulier</a>
</body>
</html>
</body>
</html>