PHP Using session variables in array(s)
Posted
by Chris
on Stack Overflow
See other posts from Stack Overflow
or by Chris
Published on 2010-05-02T14:48:11Z
Indexed on
2010/05/02
14:57 UTC
Read the original article
Hit count: 225
Hello,
My question is how do i put these session variables into a array? I have tried countless ways but none of them work.
Not really sure what to put in a array and what no and how to adress them.
Currently when i fill in the form the data gets displayed in a table.
Next when i press the hyperlink that takes me back to the same form, i wish to enter data again.
This data should be added in a new row in the same display table.
Best 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;
$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");
}
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>
</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;
$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))
{
$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>
© Stack Overflow or respective owner