尝试创建多个表行时,PHP UndefinedIndex

时间:2010-05-18 09:11:30

标签: php

以下程序在给定表格时计算一些输入 我想要实现的是,当我返回表单输入新数据时,它会在表中添加一个新的表行。

我一直得到unfind索引,我无法在我的表中获得多行。 注意:未定义的索引:文件名
注意:未定义索引:大小
注意:未定义的索引:floor 注意:未定义的索引:电话
注意:未定义索引:网络

我正在正确地对待桌子吗?

问候。

文件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>

文件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>

1 个答案:

答案 0 :(得分:2)

当您从会话中读取时,您使用小写字母t表。

$ Table = $ _SESSION ['table']; 

当你把它写回来时,你使用大写字母T表。

$ _SESSION ['Table'] = $ table; 

他们是不同的。

尝试使用类似print_r($_SESSION);的内容来帮助您调试此类问题......

也..

你的初始if语句可能有错误的逻辑方式。应该这样......

if (empty ($ _POST)) 

if (!empty ($ _POST))