2009-07-19 13 views
0

Hallo Ich versuche, ein Formular an die Person, die diese Formulare als Referenzen ausfüllen zurück zu senden. Jedoch bekomme ich immer Fehler in Zeile 5. Was ich sehe kein Problem. Kann mir jemand helfen? Vielen Dank!Formular ausfüllen Problem

<?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> 

Antwort

1

; fehlt nach require_once() in der zweiten Zeile. Ich weiß nicht warum, sagt Fehler in Zeile 5, vielleicht haben Sie einige Kommentare gelöscht?

+0

zugreifen kann ich tat denke, das Problem wurde und jetzt bekomme ich einen neuen Fehler. "undefinierten Index für alle Variablen" –

+0

Überprüfen Sie, wie Ihr POST aussieht, geben Sie einfach var_dump ($ _ POST); – usoban

+0

Pflege um mehr zu erarbeiten? Sorry, ich bin nicht gut in diesem .. –

0

Ich sehe viele Probleme in dem Codeausschnitt, den Sie gepostet haben, aber der einzige, der mir in den Sinn kommt, der in Zeile 5 sein könnte, ist, dass $ _POST ['Kursname'] nicht gesetzt ist.

Allerdings, ohne zu wissen, was die Form, die die Werte durch geschrieben hat, aussieht, ist es unmöglich zu sagen.

+0

Hmm .. bedeutet ich verpasse etwas? –

0

Die Seite kommt in 3 Sets.

Erste Seite:

<? 
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> 

Zweite ein

<?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> 

Finale ist die, auf meinem ersten Beitrag.

0

Ich bin ziemlich sicher, dass das Formular-Tag nach dem Body-Tag kommen muss, aber das ist ein kleines Problem. Ihr zweiter Code-Code hängt eine Zahl am Ende jeder Post-Variable an, aber Ihr letzter Codeabschnitt scheint das nicht zu reflektieren.

Statt Zahlen am Ende jeder Formularvariablen, verwenden Sie Array statt, wie diese

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

Es wird ein geworden, die Sie über

$nric = $_POST["nric"]; 
echo "<pre>".print_r($nric, true)."</pre>"; 
+0

Ich sehe ... Aber was, wenn ich nur die erste Tabelle an den Benutzer mailen möchte, der diese Informationen eingibt? $ class_name und etc .. Nicht das Studentenformular. Weil mein Feedback-Code nicht funktioniert. Es heißt, ich habe für alle Variablen einen undefinierten Index. –

Verwandte Themen