Php 使用多个复选框
我是php新手。请帮我解决这个问题!!! 我有一份html和php的学生申请表。。带有文本框和复选框。我无法读取复选框的值。请帮我找出我的代码有什么问题。这是我的html代码和php代码 index.phpPhp 使用多个复选框,php,html,Php,Html,我是php新手。请帮我解决这个问题!!! 我有一份html和php的学生申请表。。带有文本框和复选框。我无法读取复选框的值。请帮我找出我的代码有什么问题。这是我的html代码和php代码 index.php <div class="formWrapper"> <div class="formLeft"> <h4>Admission to LKG</h4> <form name="LKGFor
<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>
LKG入学
学名
学生出生日期
Ex:2014年1月1日
父名
母亲姓名
电子邮件地址
手机号码
居住地址
城市
Pin码
家长是这所学校的校友(老男孩)
是的
否
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>
$studentName=”“;
$studentDOB=“”;
$parentName=“”;
$motherName=“”;
$email=“”;
$contact=“”;
$address=“”;
$city=“”;
$pincode=“”;
$Almnus=“”;
$formType=“”;
如果($_请求[“formType”]=“LKG”){
$studentName=$\请求[“LKGStudentName”];
$studentDOB=$_请求[“lkgsstudentdob”];
$parentName=$\请求[“LKGParentName”];
$motherName=$_请求[“LKGMotherName”];
$email=$_请求[“LKGEmail”];
$contact=$\请求[“LKGContactNumber”];
$address=$_请求[“LKGAddress”];
$city=$_请求[“LKGCity”];
$pincode=$\u请求[“LKPincode”];
$Almnus=$_请求[“LKGAlmnus”];
$formType=“LKG”;
}
$username=“root”;
$password=“”;
$hostname=“localhost”;
$db=“abc”;
//与数据库的连接
$dbhandle=mysql_connect($hostname、$username、$password)或die(“无法连接到mysql”);
mysql_select_db($db,$dbhandle)或die('cannotselect db');
mysql_查询(“插入招生信息(学生姓名、家长姓名、电子邮件地址、电话、类型、出生日期、母亲姓名、地址、城市、密码、almnus))
值(“$studentName”、“$parentName”、“$email”、“$contact”、“$formType”、“$studentDOB”、“$motherName”、“$address”、“$city”、“$pincode”、“$Almnus”)或die(mysql_error());
//添加页面
$pdf->AddPage();
$html='1
$html.=$formType;
$html.='
网上报名表格详情
学名
';
$html.=$studentName;
$html.='
学生出生日期
';
$html.=$studentDOB;
$html.='
父名称
$html.=$parentName;
$html.='
母亲姓名
';
$html.=$motherName;
$html.='
电子邮件地址
';
$html.=$email;
$html.='
联系电话
';
$html.=$contact;
$html.='
居住地址
';
style=“border:1px solid#ccc;”>;
$html.=$address;
$html.='
城市
';
$html.=$city;
$html.='
Pin码
';
$html.=$pincode;
$html.='
阿尔姆努斯
';
$html.=$Almnus;
$html.='
您的输入错误导致名称不匹配:LKGAlumnus
然后是LKGAlmnus
。第一个有两个u,第二个只有一个u
<input type="checkbox" name="LKGAlumnus" value="Yes" id="LKGAlmnus" >Yes   
<input type="checkbox" name="LKGAlumnus" value="No" id="LKGAlmnus" >No       
//...
$Almnus= $_REQUEST["LKGAlmnus"];
是
否
//...
$Almnus=$_请求[“LKGAlmnus”];
如果要获取以下任一选项,应使用单选按钮而不是复选框:
HTML:
<input type="radio" name="LKGAlumnus" value="Yes" id="LKGAlmnusYes" >Yes</input>
<input type="radio" name="LKGAlumnus" value="No" id="LKGAlmnusNo" >No </input>
$Almnus= $_POST["LKGAlumnus"];
既然似乎没有一个回答者能在一个答案中得到全部的答案,我想我必须这样做 问题:
$Almnus= $_REQUEST["LKGAlumnus"]; // watch the spelling, Get the NAME
这是带有一个复选框的解决方案
<input type="checkbox" name="LKGAlumnus" value="Yes" id="LKGAlumnusYes" />
<label for="LKGAlumnusYes">Alumnus?</label>
男校友
这是两台收音机的解决方案
Alumnus?<input type="radio" name="LKGAlumnus" value="Yes" id="LKGAlumnusYes"/>
<label for="LKGAlumnusYes">Yes</label>
<input type="radio" name="LKGAlumnus" value="No" id="LKGAlumnusNo" />
<label for="LKGAlumnusNo">No</label>
校友?
对
不
您搜索了吗?嗯。。但是我没有发现我的代码有什么问题。也许在这种情况下使用单选按钮更好?您可以使用一个复选框来表示是/否,或者使用两个选项的单选按钮。1)更改为单选,2)使用PHP中的名称来获取值3)使用唯一ID,但对Radio使用相同的名称将名称发送到服务器,因此它是他需要匹配的名称!这基本上是一个简略的评论,你没有使ID是唯一的,所以你没有正确地阅读所有的ID。为你确定了ID。