我新來php.Please幫我出來這個! 我有一個學生申請表格在HTML和PHP ..與文本框和複選框。我無法讀取複選框的值。請幫我的代碼錯了什麼。這是我的HTML代碼和PHP代碼,以及使用多個複選框
的index.php
<div class="formWrapper">
<div class="formLeft">
<h4>Admission to LKG</h4>
<form name="LKGForm" id="LKGForm" method="POST" action="pdf/pdf.php">
<div class="formItem">
<label>Student Name</label>
<input type="text" name="LKGStudentName" id="LKGStudentName" />
</div>
<div class="formItem">
<label>Student Date of Birth</label>
<input type="text" name="LKGStudentDOB" id="LKGStudentDOB" />
Ex: 01-Jan-2014
</div>
<div class="formItem">
<label>Father Name</label>
<input type="text" name="LKGParentName" id="LKGParentName" />
</div>
<div class="formItem">
<label>Mother Name</label>
<input type="text" name="LKGMotherName" id="LKGMotherName" />
</div>
<div class="formItem">
<label>Email Address</label>
<input type="text" name="LKGEmail" id="LKGEmail" />
</div>
<div class="formItem">
<label>Mobile Number</label>
<input type="text" name="LKGContactNumber" id="LKGContactNumber" />
</div>
<div class="formItem">
<label>Residential Address</label>
<input type="text" name="LKGAddress" id="LKGAddress" />
</div>
<div class="formItem">
<label>City</label>
<input type="text" name="LKGCity" id="LKGCity" value="Bangalore" />
</div>
<div class="formItem">
<label>Pin Code</label>
<input type="text" name="LKGPincode" id="LKGPincode" />
</div>
<label>Parent is an Alumnus (old Boy) of this school </label>   
<input type="checkbox" name="LKGAlumnus" value="Yes" id="LKGAlmnus" >Yes   
<input type="checkbox" name="LKGAlumnus" value="No" id="LKGAlmnus" >No       
<div class="formItem">
<input type="hidden" name="formType" id="formType" value="LKG" />
<input type="button" name="LKGSubmit" id="LKGSubmit" value="Submit" class="formButton" />
</div>
</form>
pdf.php
$studentName = "";
$studentDOB = "";
$parentName = "";
$motherName = "";
$email = "";
$contact = "";
$address = "";
$city = "";
$pincode = "";
$Almnus="";
$formType = "";
if($_REQUEST["formType"] == "LKG") {
$studentName = $_REQUEST["LKGStudentName"];
$studentDOB = $_REQUEST["LKGStudentDOB"];
$parentName = $_REQUEST["LKGParentName"];
$motherName = $_REQUEST["LKGMotherName"];
$email = $_REQUEST["LKGEmail"];
$contact = $_REQUEST["LKGContactNumber"];
$address = $_REQUEST["LKGAddress"];
$city = $_REQUEST["LKGCity"];
$pincode = $_REQUEST["LKGPincode"];
$Almnus= $_REQUEST["LKGAlmnus"];
$formType = " LKG";
}
$username = "root";
$password = "";
$hostname = "localhost";
$db = "abc";
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
mysql_select_db($db,$dbhandle) or die('cannot select db');
mysql_query("INSERT INTO admissions (studentname, parentname, emailaddress, phone, type, dob, mothername, address, city, pincode, almnus)
VALUES('$studentName', '$parentName', '$email', '$contact', '$formType', '$studentDOB', '$motherName', '$address', '$city', '$pincode', '$Almnus') ") or die(mysql_error());
// add a page
$pdf->AddPage();
$html = '
<h1> </h1>
<h1> </h1>
<h1> </h1>
<h1> </h1>
<h1> </h1>
$html .= $formType;
$html .= '</h3>
<table cellspacing="0" cellpadding="50">
<tr>
<td>
<table cellspacing="0" cellpadding="10">
<tr>
<td colspan="2" bgcolor="#f1f1f1" color="#000" align="left" style="border: 1px solid #ccc;border-top: 1px solid #ccc;"><h4>Online Admission Form Details</h4></td>
</tr>
<tr>
<td width="30%" style="border: 1px solid #ccc;">Student Name</td>
<td width="70%" style="border: 1px solid #ccc;">';
$html .= $studentName;
$html .= '</td>
</tr>
<tr>
<td width="30%" style="border: 1px solid #ccc;">Student Date of Birth</td>
<td width="70%" style="border: 1px solid #ccc;">';
$html .= $studentDOB;
$html .= '</td>
</tr>
<tr>
<td style="border: 1px solid #ccc;">Parent Name</td>
<td style="border: 1px solid #ccc;">
$html .= $parentName;
$html .= '</td>
</tr>
<tr>
<td style="border: 1px solid #ccc;">Mother Name</td>
<td style="border: 1px solid #ccc;">';
$html .= $motherName;
$html .= '</td>
</tr>
<tr>
<td style="border: 1px solid #ccc;">Email Address</td>
<td style="border: 1px solid #ccc;">';
$html .= $email;
$html .= '</td>
</tr>
<tr>
<td style="border: 1px solid #ccc;">Contact Number</td>
<td style="border: 1px solid #ccc;">';
$html .= $contact;
$html .= '</td>
</tr>
<tr>
<td style="border: 1px solid #ccc;">Residential Address</td>
<td style="border: 1px solid #ccc;">';
style="border: 1px solid #ccc;">';
$html .= $address;
$html .= '</td>
</tr>
<tr>
<td style="border: 1px solid #ccc;">City</td>
<td style="border: 1px solid #ccc;">';
$html .= $city;
$html .= '</td>
</tr>
<tr>
<td style="border: 1px solid #ccc;">Pin Code</td>
<td style="border: 1px solid #ccc;">';
$html .= $pincode;
$html .= '</td>
</tr>
<tr>
<td style="border: 1px solid #ccc;">Almnus</td>
<td style="border: 1px solid #ccc;">';
$html .= $Almnus;
$html .= '</td>
</tr>
</table>
</td>
</tr>
</table>
你搜索解決方案? http://stackoverflow.com/search?q=%5Bphp%5D+checkboxes – mplungjan
亞..但我沒有得到什麼錯我的代碼.. – user3286350
也許是在這種情況下使用單選按鈕更好?您可以使用一個複選框來指示是/否,或者使用單選按鈕提供兩種選擇。 –