PHP UndefinedIndex while trying to create multiple table rows
The following program calculates some input when given into a form.
The thing i am trying to achieve is that it adds a new table row into the table when i go back to the form to enter new data.I keep getting undefind index and i am not able to get multiple rows in my table. Notice: Undefined index: file name
Notice: Undefined index: size Notice: Undefined index: floor Notice: Undefined index: phone Notice: Undefined index: networkAnd am i adressing the table correctly?
Regards.
File 1: ExpoFormulier.php
<? 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> Expo Form </ title>
<meta HTTP-EQUIV="Content-Type" content="text/html; charset=utf-8" />
</ Head>
<body>
<? Php
if (empty ($ _POST))
(
$ File name = $ _POST ['state name'];
$ Area = $ _开发者_运维百科POST ['size'];
$ Floor = isset ($ _POST ['floor'])? $ _POST ['Floor']: 0, / / if checkbox checked value 1 else 0
$ Phone = isset ($ _POST ['phone'])? $ _POST ['Phone']: 0;
$ Network = isset ($ _POST ['network'])? $ _POST ['Network']: 0;
/ / Control surface
if (is_numeric ($ size)) / / OK
(
if (isset ($ _SESSION ['table']))
(
/ / Create a new row to the existing session table
$ Table = $ _SESSION ['table'];
$ Number = count ($ table);
$ Table [$ count] [0] = $ file name;
$ Table [$ count] [1] = $ size;
$ Table [$ count] [2] = $ floor;
$ Table [$ count] [3] = $ phone;
$ Table [$ count] [4] = $ network;
$ _SESSION ['Table'] = $ table;
)
else
(
/ / Create the session table
$ Table [0] [0] = $ file name;
$ Table [0] [1] = $ size;
$ Table [0] [2] = $ floor;
$ Table [0] [3] = $ phone;
$ Table [0] [4] = $ network;
$ _SESSION ['Table'] = $ table;
)
header ("Location: ExpoOverzicht.php");
)
else
(
echo "Wrong <h1> area - New attempt </ h1>";
)
)
?>
<Form action = "<? Php echo $ _SERVER ['PHP_SELF'];?>" Method = "post" id = "Form1">
<h1> Enter details </ h1>
<table>
<tr>
<td> Stand Name: </ td>
<td> <input name="standnaam" size="18"/> </ td>
</ Tr>
<tr>
<td> Area (m ^ 2): </ td>
<td> <input name="oppervlakte" size="6"/> </ td>
</ Tr>
<tr>
<td> Floor: </ td>
<td> <input type="checkbox" name="verdieping" value="1"/> </ td>
<! - Value to set up a checkbox! is checked if value 1 ->
</ Tr>
<tr>
<td> Phone: </ td>
<td> <input type="checkbox" name="telefoon" value="1"/> </ td>
</ Tr>
<tr>
<td> Network: </ td>
<td> <input type="checkbox" name="netwerk" value="1"/> </ td>
</ Tr>
<tr>
<td> <input type="submit" name="verzenden" value="Verzenden"/> </ td>
</ Tr>
</ Table>
</ Form>
</ Body>
</ Html>
File 2: ExpoOverzicht.php
<? 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> Expo Overview </ title>
<meta HTTP-EQUIV="Content-Type" content="text/html; charset=utf-8" />
<link href="StyleSheetExpo.css" rel="stylesheet" type="text/css" />
</ Head>
<body>
<h1> List of stocks entered in this session </ h1>
<? Php
$ File name = $ _SESSION ['state name'];
$ Size = $ _SESSION ['size'];
$ Floor = $ _SESSION ['floor'];
$ Telephone = $ _SESSION ['phone'];
$ Network = $ _SESSION ['network'];
$ Result1 = 0, / * each déclare else error "undefined variable" * /
$ Result2 = 0;
$ Result3 = 0;
$ PrijsCom = 0;
Floor price = $ 0;
for ($ i = 1, $ i <= $ size, $ 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 (floor == $ 1)
(
Floor price = $ 120 * $ size;
)
if (($ phone == 1) | | ($ network == 1)) / / OR condition first read this or else the code uses only 20
(
$ PrijsCom = 20;
)
if (($ phone == 1) & & ($ network == 1))
(
$ PrijsCom = 30;
)
Price $ total = $ price + $ prijsOpp Floor + $ prijsCom;
$ Values = array ($ file name, $ size, $ floor, $ telephone, $ network, $ total Prize);
echo "<table class=\"tableExpo\">;
echo "<th> State Name </ th>";
echo "<th> Size </ th>";
echo "<th> Floor </ th>";
Echo '<th> Phone </ th> ";
echo "<th> Network </ th>";
echo "<th> Total Price </ th>";
/ / For ($ i = 0, $ i <count ($ values); $ i + +)
/ / (
echo "<tr>;
echo "<td>. $ file name." </ td> ";
echo "<td>. $ surface." </ td> ";
echo "<td>. $ floor." </ td> ";
echo "<td>. $ telephone." </ td> ";
echo "<td>. $ network." </ td> ";
echo "<td>. $ total price." </ td> ";
echo "</ tr>";
/ /)
echo "</ table>";
?>
<a href="ExpoFormulier.php"> Back to form </ a>
</ Body>
</ Html>
When you read from your session you use a lower case t for table.
$ Table = $ _SESSION ['table'];
When you write it back, you use an upper case T for table.
$ _SESSION ['Table'] = $ table;
They are different.
Try using something like print_r($_SESSION);
to help you debug this kind of problem...
also..
Your initial if statement might have the logic the wrong way around. should this...
if (empty ($ _POST))
be
if (!empty ($ _POST))
精彩评论