填表问题

时间:2009-07-19 09:10:25

标签: php email forms feedback

您好我正在尝试将某些表格发回给填写这些表格的人作为参考。但是我在第5行继续收到错误。我没有看到任何问题。谁能指导我?谢谢!

<?php session_start(); 
require_once 'opendb.php'

$subject = "Refrence";
$refemail = "Here is the list for your refrence";
$class_name = $_POST['course_name'];
$class_venue = $_POST['class_venue'];
$date_of_lesson =$_POST['date_of_lesson'];
$time_of_lesson =$_POST['time_of_lesson'];
$class_duration =$_POST['class_duration'];
$date_of_exam =$_POST['date_of_exam'];
$class_in_charge =$_POST['class_in_charge'];    
$contact =$_POST['contact'];
$email =$_POST['email'];
$zone =$_POST['zone_no'];
$cl_name =$_POST['cl_name'];
$ce_name =$_POST['ce_name'];

$todayis = date("l, F j, Y, g:i a") ;

$message = " $todayis \n
From: $cl_name ($email)\n
Class name: $class_name \n
Class Venue: $class_venue \n
Date of lesson: $date_of_lesson \n
Time of lesson: $time_of_lesson \n
Class duration: $class_duration \n
Date of exam: $date_of_exam \n
Class in charge: $class_in_charge \n
Contact: $contact \n
Zone: $zone \n
Cl Name: $cl_name \n
Ce Name: $ce_name \n
";

$from = "From: $email\r\n";

mail($email, $subject, $refemail, $message, $from);
?>

<img style="width: 190px; height: 184px;" alt=""
src="images/Picture1.jpg">
<form enctype="multipart/form-data" action = 'function.php' method='post' />
</head>
<body>
<span
 style="text-decoration: underline; font-weight: bold;"> </span>

 <head><title>Success!</title></head>
<h1>Class Successfully Created !</h1>
<h3>Thank you. An email has been sent to your account for futher reference.</h3>

<?
// Read variables from the $_POST array


$i = 0;
while ($i < $_SESSION['numberOfStudents'])
{
$student_name = $_POST['student_name'.$i.''];
$classId = $_SESSION['class_id'];
$nric = $_POST['nric'.$i.''];
$age = $_POST['age'.$i.''];
$sql = "INSERT INTO b_student (bs_nric_no,student_name,age,b_class_id) VALUES 
            ('$nric','$student_name','$age','$classId')";

mysql_query($sql) or die(mysql_error());

$i++;
}


?>

<tr>
            <td></td>
            <table style="text-align: left;"
            <td><input type = 'submit' value = 'Back to Function List!'></td>

        </tr>
    </table>
</form>
</html>
</body>
</html>

4 个答案:

答案 0 :(得分:1)

在第二行中的require_once()之后缺少。不知道为什么在第5行说错误,也许你清除了一些评论?

答案 1 :(得分:0)

我在你发布的代码片段中看到很多问题,但是唯一想到的可能是第5行的问题是$ _POST ['course_name']没有设置。

但是,如果不知道发布值的形式是什么样的话,就不可能说了。

答案 2 :(得分:0)

该网站有3套。

第一站点:

<?
session_start();
require_once 'opendb.php';
?>
<html>
<form action="student_details.php" method="post">
<img style="width: 190px; height: 184px;" alt=""
src="images/Picture1.jpg">

<body>
<span
 style="text-decoration: underline; font-weight: bold;"> </span><big
 style="font-weight: bold;"><big><big><big>Create New Class</big></big></big></big>
 </head>

<?


            echo "<td><h3>Application for Registration of
            <select name='course_name' id='drop_down'></td><h3>";
            $sql= "SELECT DISTINCT course_name FROM c_course";
            $result=mysql_query($sql);
            echo "</tr>";

            while  ($row = mysql_fetch_assoc($result))
            {
            echo "<option>";
            echo $row['course_name'];
            echo "</option>";

            }
            echo "</td>";
            echo "</tr>";


          ?>



    <table>

        <tr>
           <td>Venue of Class:</td>
            <td><input type = 'text' name = 'class_venue'></td>
            </tr>
        <tr>
            <td>Date of Commencement:</td>
            <td><input type = 'text' name = 'date_of_lesson'></td>
        </tr>
        <tr>
        <td>Other Dates of Lessons:</td>
        <td><input type = 'text' name = 'other_lessons'></td>
        <td><input type = 'text'  name = 'other_lessons1'></td>

        <tr>
            <td>Time:</td><td><select name="time_of_lesson" id="drop_down">
             <option value="0700">0700</option> 
             <option value="0800">0800</option>
             <option value="0900">0900</option>
            </tr>
            <tr>
             <td> Class Duration:</td><td><select name="class_duration" id="drop_down">
             <option value="1">1</option> 
             <option value="2">2</option>
             <option value="3">3</option>
             <option value="4">4</option> 
             <option value="5">5</option>
             <option value="6">6</option>

             </tr>
             <tr>
             <td>Tentative Date of Exam:</td>
            <td><input type = 'text'  name = 'date_of_exam'></td>
            <td>(DD-MM-YYYY)</td>
        </tr>

        <tr>
            <td>Class-In-Charge:</td>
            <td><input type = 'text' name = 'class_in_charge'></td>
            </td>
            <tr>
            <td>Contact No:</td>
            <td><input type = 'text' name = 'contact'></td>
            </tr>
            <tr>
            <td>Email:</td>
            <td><input type = 'text' name = 'email'></td>
            </tr>
<?

$i=1;
            echo "<tr>";
            echo "<td><u>Choose Lecturer:</u></td>";
            echo "</tr>";



            echo "<tr>";
            echo "<td>Zone:</td>";
            echo "<td><select name='zone_no' id='drop_down'>";
            $sql= "SELECT DISTINCT zone_no FROM c_lecturer";
            $result=mysql_query($sql);

            while  ($row = mysql_fetch_assoc($result))
            {
            echo "<option>";
            echo $row['zone_no'];
            echo "</option>";

            }
            echo "</td>";
            echo "</tr>";


            echo "<tr>";
            echo "<td>Lecturer:</td>";
            echo "<td><select name='cl_name' id='drop_down'>";
            $sql= "SELECT cl_name FROM c_lecturer";
            $result=mysql_query($sql);

            while  ($row = mysql_fetch_assoc($result))
            {
            echo "<option>";
            echo $row['cl_name'];
            echo "</option>";

            }
            echo "</td>";
            echo "</tr>";



            echo "<tr>";
            echo "<td>Examiner:</td>";
            echo "<td><select name='ce_name' id='drop_down'>";
            $sql= "SELECT ce_name FROM c_examiner";
            $result=mysql_query($sql);

            while  ($row = mysql_fetch_assoc($result))
            {
            echo "<option>";
            echo $row['ce_name'];
            echo "</option>";

            }
            echo "</td>";
            echo "</tr>";
?>
<br>
<br>
      <tr>
        <td><input type = 'submit' name="StudentDetails" value = "Continue"></td>
        </tr>
    </table>
</form>
</body>
</html>

第二个

<?php
error_reporting(E_ALL ^ E_NOTICE);

session_start();
require_once 'opendb.php';

if (isset($_POST['AddStudent'])) {
// If user click on Add new student button 
    $temp = $_SESSION['numberOfStudents'];
    $temp = $temp + 1;
    $_SESSION['numberOfStudents'] = $temp;
}
/*else if (isset($_POST['FinalCheckBtn'])) {
// If user click on Final Check button go to Final check page
header('Location: http://localhost/SJAA/final_check.php') ;
}*/
else {
// if User enter this page the first time from "create new class page " 
    // the variable that hold the credentials to connect to the database

    // Read variables from the $_POST array
    $class_name = $_POST['course_name'];
    $class_venue = $_POST['class_venue'];
    $date_of_lesson =$_POST['date_of_lesson'];
    $time_of_lesson =$_POST['time_of_lesson'];
    $class_duration =$_POST['class_duration'];
    $date_of_exam =$_POST['date_of_exam'];
    $class_in_charge =$_POST['class_in_charge'];    
    $contact =$_POST['contact'];
    $email =$_POST['email'];
    $zone =$_POST['zone_no'];
    $cl_name =$_POST['cl_name'];
    $ce_name =$_POST['ce_name'];

    // Prepare the query

    $sql = "INSERT INTO b_class (class_name,class_venue,date_of_lesson,time_of_lesson,class_duration,date_of_exam,class_in_charge,contact,email,zone_no, cl_name,ce_name) VALUES 
                ('$class_name','$class_venue','$date_of_lesson','$time_of_lesson','$class_duration','$date_of_exam','$class_in_charge','$contact','$email','$zone_no','$cl_name','$ce_name')";
    // Execute the query
    mysql_query($sql) or die(mysql_error());
    $_SESSION['numberOfStudents'] = 0;
    $_SESSION['class_name']=$_POST['course_name'];
    $_SESSION['class_venue'] = $_POST['class_venue'];
    $_SESSION['date_of_lesson'] = $_POST['date_of_lesson'];
    $_SESSION['time_of_lesson'] = $_POST['time_of_lesson'];
    $_SESSION['class_duration'] = $_POST['class_duration'];
    $_SESSION['date_of_exam'] = $_POST['date_of_exam'];
    $_SESSION['class_in_charge'] = $_POST['class_in_charge'];
    $_SESSION['contact'] = $_POST['contact'];
    $_SESSION['email'] = $_POST['email'];
    $_SESSION['zone_no'] = $_POST['zone_no'];
    $_SESSION['cl_name'] = $_POST['cl_name'];
    $_SESSION['ce_name'] = $_POST['ce_name'];



    // Prepare query to get the new class id 
    $sql = "select max(b_class_id) as ClassId from b_class";
    $result = mysql_query($sql) or die(mysql_error());
    if (mysql_num_rows($result) > 0) {
        $row = mysql_fetch_row($result);
        $_SESSION['class_id'] = $row[0]; 
    }


}
?>
<html>
<form enctype="multipart/form-data" action = 'student_details.php' method='post'>
<img style="width: 190px; height: 184px;" alt="" src="images/Picture1.jpg">

<head><title>Students' Particulars</title></head>
<h1>Students' Particulars</h1>
<h3> Please enter student's particulars. All fields are to be filled. </h3>
<table style="text-align: left; width: 333px; height: 144px;"
 border="1" cellpadding="2" cellspacing="2">
  <tbody>
    <tr>
      <td><?php 
echo "Class Name: "; 
echo $_SESSION['class_name'];?> </td>
</tr>
<tr>
      <td><?php 
echo "Class Id: "; 
echo $_SESSION['class_id'];?> </td>
</tr>
    <tr>
      <td><?php 
echo "Class Venue: "; 
echo $_SESSION['class_venue'];?> </td>
</tr>
<tr>
      <td><?php 
echo "Date of Commencement: "; 
echo $_SESSION['date_of_lesson'];?> </td>
</tr>
<tr>
      <td><?php 
echo "Time: "; 
echo $_SESSION['time_of_lesson'];?> </td>
</tr>
<tr>
      <td><?php 
echo "Class Duration: "; 
echo $_SESSION['class_duration'];?> </td>
</tr>
<tr>
      <td><?php 
echo "Tentative Date of Exam: "; 
echo $_SESSION['date_of_exam'];?> </td>
</tr>
<tr>
      <td><?php 
echo "Class-In-Charge: "; 
echo $_SESSION['class_in_charge'];?> </td>
</tr>
<tr>
      <td><?php 
echo "Contact: "; 
echo $_SESSION['contact'];?> </td>
</tr>
<tr>
      <td><?php 
echo "Email: "; 
echo $_SESSION['email'];?> </td>
</tr>
<tr>
   <td><?php 
echo "Zone: "; 
echo $_SESSION['zone_no'];?> </td>
</tr>
<tr>
   <td><?php 
echo "Lecturer: "; 
echo $_SESSION['cl_name'];?> </td>
</tr>
<tr>
   <td><?php 
echo "Examiner: ";
echo $_SESSION['ce_name'];?> </td>
</tr>

</tr>
<body>
<table border="1">
<tr>
<th>Name</th>
<th>NRIC no.</th>
<th>Age</th>
</tr>
<br>
<input type="submit" value="Add new Student" name="AddStudent">
</form>
<?php 
$cnt = 0;
echo "<form enctype='multipart/form-data' action = 'final_check.php' method='post'>";
while ($cnt < $_SESSION['numberOfStudents']) {


    $NameCnt = "Name".$cnt;
    $NRICcnt = "NRICno".$cnt;
    $AgeCnt = "Age".$cnt;

    if (isset($_POST[$NameCnt])) {
?> 
        <tr>
        <td><input type = 'text' name = 'student_name<?php echo $cnt ?>' value='<?php echo $_POST[$NameCnt] ?>'></td>
        <td><input type = 'text' name = 'nric<?php echo $cnt ?>' value='<?php echo $_POST[$NRICcnt] ?>'></td>
        <td><input type = 'text' name = 'age<?php echo $cnt ?>' value='<?php echo $_POST[$AgeCnt] ?>'></td>
        </tr> 
<?php
    }
    else {
?> 
        <tr>
        <td><input type = 'text' name = 'student_name<?php echo $cnt ?>'></td>
        <td><input type = 'text' name = 'nric<?php echo $cnt ?>'></td>
        <td><input type = 'text' name = 'age<?php echo $cnt ?>'></td>
        </tr>
<?php
    }

$cnt = $cnt +1;
}
?>

</table>
<tr>
            <td></td>
            <table style="text-align: left;"
            <td><input type = 'submit' value = 'Submit' name='FinalCheckBtn'></td>

        </tr>
    </table>
</form>
</html>

最后一个是我第一篇文章中的那个。

答案 3 :(得分:0)

我非常确定form标签必须在body标签之后,但那是次要问题。你的第二组代码在每个post变量的末尾添加一个数字,但你的最后一段代码似乎并没有反映出这一点。

不要在每个表单变量的末尾使用数字,而是使用数组,就像这样

<input type='text' name='nric[]'>

它将成为您可以通过

访问的
$nric = $_POST["nric"];
echo "<pre>".print_r($nric, true)."</pre>";