1

所以我有两页用于测试的多页表单。当我单独测试表单的第一部分时,它工作正常。一切都根据它从我的数据库中检索到的信息进行显示。一切看起来都很棒,直到我单击提交按钮到下一页,确认所有值。当我尝试点击提交时,它应该也传递用户的输入并将它们保存为 $_POST [],它给了我一个服务器错误。我对 php 很陌生,所以我对我可能需要的一切都不太熟悉。

这是我第一部分的代码:

<?php
    $db = mysql_connect(
  ':/Applications/MAMP/tmp/mysql/mysql.sock',
  'root',
  'root'
);
        if(!$db) die("Error connecting to MySQL database.");
        mysql_select_db('onlineform', $db);

        $newQuery = mysql_query("SELECT newPrice,numberOfWeeks FROM onlineformdata ORDER BY id DESC LIMIT 1");
$newRow = mysql_fetch_row($newQuery);



        $newQuery1 = mysql_query("SELECT newCampSessions FROM onlineformdata ORDER BY id DESC LIMIT 1") or die('Error ' . mysql_error());
$newFoo = mysql_fetch_array($newQuery1);


        $newQuery2 = mysql_query("SELECT pricePerWeek FROM onlineformdata ORDER BY id DESC LIMIT 1") or die('Error ' . mysql_error());
$newFoo1 = mysql_fetch_array($newQuery2);

        $newQuery3 = mysql_query("SELECT numberOfSchools FROM onlineformdata ORDER BY id DESC LIMIT 1");
$newRow1 = mysql_fetch_row($newQuery3);

        $newQuery4 = mysql_query("SELECT schools FROM onlineformdata ORDER BY id DESC LIMIT 1") or die('Error ' . mysql_error());
$newFoo2 = mysql_fetch_array($newQuery4);

$newOldString = $newFoo['newCampSessions'];
$newOldString2 = $newFoo1['pricePerWeek'];
$newOldString3 = $newFoo2['schools'];



$newChangedString = unserialize($newOldString);
$newChangedString2 = unserialize($newOldString2);
$newChangedString3 = unserialize($newOldString3);

$_SESSION['quickVariable'] = $newChangedString2;

settype($newRow[1], "integer");

$limit = $newRow[1];
$anotherLimit = $newRow1[0];
mysql_close();


?>
<!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>
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.7.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.10/jquery-ui.js"></script>


<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<link type="text/css" rel="stylesheet" href="stylesheet.css"/>
<link href='http://fonts.googleapis.com/css?family=Alef' rel='stylesheet' type='text/css'>
<link type="text/css" rel="stylesheet" href="style3.css"/>
<script type="text/javascript" src="JavaScript.js">
</script>
 <script type="text/javascript">var jslang='EN';
 </script>
        <link href="http://activemindandbody.orgStyleSheets/ModuleStyleSheets.css" rel="StyleSheet" type="text/css" />
        <script type="text/javascript">var jslang='EN';
        </script>
        <link href="http://activemindandbody.org/style.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="js/modernizr.custom.04022.js"></script>
        <link href='http://fonts.googleapis.com/css?family=Open+Sans+Condensed:700,300,300italic' rel='stylesheet' type='text/css'>
        <link href='http://fonts.googleapis.com/css?family=Alef' rel='stylesheet' type='text/css'>
    </head>
    <body>
        <!-- BC_OBNW -->
        <div id="container">
            <div id="header"><div id="header_text" style="top: 118px; left: 23px;">
                <p>Make a donation today and help&nbsp;&nbsp;âCreating a Brighter Future                      
    Together.â&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; <a href="http://activemindandbody.org/donation.html">Make a donation now !</a> </p>
        </div>
        </div>
        <div id="content">
                    <section class="tabs">
                <input id="tab-1" type="radio" name="radio-set" class="tab-selector-1" checked="checked" />
                <label for="tab-1" class="tab-label-1">1. Camper's Info</label>

                <input id="tab-2" type="radio" name="radio-set" class="tab-selector-2" />
                <label for="tab-2" class="tab-label-2">2. Parent's Info</label>

                <input id="tab-3" type="radio" name="radio-set" class="tab-selector-3" />
                <label for="tab-3" class="tab-label-3">3. Emergency<br/> Contacts</label>

                <input id="tab-4" type="radio" name="radio-set" class="tab-selector-4" />
                <label for="tab-4" class="tab-label-4">4. Camper's Ride Home</label>

                <input id="tab-5" type="radio" name="radio-set" class="tab-selector-5" />
                <label for="tab-5" class="tab-label-5">5. <br/> Camp Days & Prices</label>

                 <input id="tab-6" type="radio" name="radio-set" class="tab-selector-6" />
                <label for="tab-6" class="tab-label-6">6. Confirm your details</label>

                <input id="tab-7" type="radio" name="radio-set" class="tab-selector-7" />
                <label for="tab-7" class="tab-label-7">7. <br />Paypal</label>
                    </section>

                <div class="clear-shadow"></div>

                <div class="content indent">

<form id="paymentform" action="amd8.php" method="post">
<br/>
<br />
   <label><b>Camp Sessions: 1-6 (Check off the week(s) the camper will be participating in.)</b> </label><br /><br />
   <ol>
   <?php  
for ($count = 0; $count < $limit; $count=$count+1)
        {
            echo"<li>"; echo $newChangedString[$count]; echo '($'; echo $newChangedString2[$count]; echo '/child)<input type=checkbox name="campsessions[]" value="'; echo $newChangedString[$count]; echo '"></li>'; 
        }

     ?>
   </ol>
    <br/>
    <label><b>Select camp location:</b> </label><br /><br />


    <select name="schoolChoice">
 <?php  

for ($count1 = 0; $count1 < $anotherLimit; $count1=$count1+1)
        {

            echo"<option value="; echo $newChangedString3[$count1]; echo '">'; echo $newChangedString3[$count1]; echo "</option>";        
        }

?> 
    </select>
<br/><br/>



 <input type="hidden" name="totalprice" />  
<input type="submit" name="formSubmit" value="Submit" class="button greenButton"/>
<input type="button" name="cancel" value="Cancel" class="button redButton" onclick="href='activemindandbody.org'">

</form>



                </div>

        </div>
    </body>
</html>

对于以下页面:(当我单击上一页上的提交时未加载的页面,而是给我一个“服务器错误”)

<?php
session_start();

if($_POST['formSubmit'] == "Submit")
{
    $errorMessage="";

    if (empty($_POST['campsessions[]'])) 
    {
        $errorMessage .="";
    }
    if (empty($_POST['campcare'])) 
    {
        $errorMessage ="";
    }
    if (empty($_POST['totalprice']))
    {
        $errorMessage ="";
    }

    $_SESSION['campcare'] = $_POST['campcare'];
    $_SESSION['campsessions'] = $_POST['campsessions'];
    $_SESSION['totalprice'] = $_POST['totalprice'];
    $_SESSION['schoolChoice'] = $_POST['schoolChoice'];
    $weeklyPrice =  $_SESSION['quickVariable'];

    $totalPrice = 0;


    while (isset($_SESSION['campsessions']))
    {   
        foreach ($weeklyPrice as $total)
            {
                $totalPrice = $totalPrice + $total;
            }
    }


}


?>


<!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>
        <title>Active Mind And Body</title>
        <!-- BC_OBNW -->
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <link href="http://activemindandbody.org/StyleSheets/ModuleStyleSheets.css"                 rel="StyleSheet" type="text/css" />
        <script type="text/javascript">var jslang='EN';</script>
        <link href="http://activemindandbody.orgStyleSheets/ModuleStyleSheets.css"                  rel="StyleSheet" type="text/css" />
        <script type="text/javascript">var jslang='EN';</script>
        <link href="http://activemindandbody.org/style.css" rel="stylesheet" type="text/            css" />
        <link rel="shortcut icon" href="../favicon.ico"> 
        <link rel="stylesheet" type="text/css" href="css/demo.css" />
        <link rel="stylesheet" type="text/css" href="style3.css" />
        <script type="text/javascript" src="js/modernizr.custom.04022.js"></script>
        <link href='http://fonts.googleapis.com/css?family=Open+Sans+Condensed:                     700,300,300italic' rel='stylesheet' type='text/css'>
        <link type="text/css" rel="stylesheet" href="stylesheet.css"/>
        <link href='http://fonts.googleapis.com/css?family=Alef' rel='stylesheet'                   type='text/css'>
        <script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.7.js"></script>
        <script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.10/jquery-ui.js"></script>
        <script src="Javascript2.js" type="text/javascript"></script>    
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    </head>
    <body>
        <!-- BC_OBNW -->
        <div id="container">
            <div id="header"><div id="header_text" style="top: 118px; left: 23px;">
                <p>Make a donation today and help&nbsp;&nbsp;âCreating a Brighter Future                      
    Together.â&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; <a href="http://activemindandbody.org/donation.html">Make a donation now !</a> </p>
        </div>
        </div>
        <div id="content">
                    <section class="tabs">
                <input id="tab-1" type="radio" name="radio-set" class="tab-selector-1" checked="checked" />
                <label for="tab-1" class="tab-label-1">1. Camper's Info</label>

                <input id="tab-2" type="radio" name="radio-set" class="tab-selector-2" />
                <label for="tab-2" class="tab-label-2">2. Parent's Info</label>

                <input id="tab-3" type="radio" name="radio-set" class="tab-selector-3" />
                <label for="tab-3" class="tab-label-3">3. Emergency<br/> Contacts</label>

                <input id="tab-4" type="radio" name="radio-set" class="tab-selector-4" />
                <label for="tab-4" class="tab-label-4">4. Camper's Ride Home</label>

                <input id="tab-5" type="radio" name="radio-set" class="tab-selector-5" />
                <label for="tab-5" class="tab-label-5">5. <br/> Camp Days & Prices</label>

                 <input id="tab-6" type="radio" name="radio-set" class="tab-selector-6" />
                <label for="tab-6" class="tab-label-6">6. Confirm your details</label>

                <input id="tab-7" type="radio" name="radio-set" class="tab-selector-7" />
                <label for="tab-7" class="tab-label-7">7. <br />Paypal</label>
                    </section>

                <div class="clear-shadow"></div>

                <div class="content indent">
<br />              
Please confirm the following details:

<p class="confirmation">
<b>SPECIAL CONSIDERATIONS AND PAYMENT INFORMATION:</b><br/><br/>
&nbsp;&nbsp;Is Camper picked up? <?php echo $_SESSION['camperpickedup'] ?> <br/><br/>
&nbsp;&nbsp;Who is picking up the camper? <?php echo $_SESSION['personPickingUpCamper'] ?> <br/><br/>
&nbsp;&nbsp;Chosen Camp Sessions: <br/>
<pre> <?php 
if(isset($_SESSION['campsessions']))
{
    foreach ($_SESSION['campsessions'] as $_SESSION['campsessions'])
    {
        echo "{$_SESSION['campsessions']}\n";
    }
}
?> 
</pre> <br />
</p> 
<p>
Total Price: $<?php echo $_SESSION['totalprice'] ?><br/><br/>
</p>
<form action="amd9.php" method="post">
<input type="submit" value='Confirm' class="button greenButton" name="formSubmit"> 
</form>



                </div>

        </div>
    </body>
</html>

抱歉,如果代码太多,请告诉我,以便我可以将其剪掉,因为上次没有提供正确的信息,我受到了很多惩罚。

但作为一个更普遍的问题,我在做什么,关于使用 php 变量来显示我的表单,好吗?还是这是大问题?

4

2 回答 2

0
while (isset($_SESSION['campsessions']))
{   
    foreach ($weeklyPrice as $total)
        {
            $totalPrice = $totalPrice + $total;
        }
}

这将是一个无限循环,因为变量永远不会被取消设置。

使用if,而不是while

于 2013-07-16T19:32:21.097 回答
0

您的代码充满了错误 - 但我想说的是让服务器关闭的是

while (isset($_SESSION['campsessions']))

等于isset($_SESSION['campsessions'])true 你不妨写

while(true)

这是一个无限循环。PHP 将超时并给您一个错误。改用 if 。

但这只是正在发生的坏事之一。我不确定您为什么要发出 5 个查询来检索表中一行的 6 个字段,并且有一个 if (empty($_POST['campsessions[]'])) 看起来不正确。

于 2013-07-16T19:33:15.847 回答