"이미 적어도 하나의 체크 박스가 PHP에 체크되어 있는지 확인하십시오"라는 질문을 발견했지만, 필자는 조직적인 사람이고 그렇지 않았기 때문에 내 요구를 충족시키지 못했습니다. 그것을하는 조직 된 방법처럼 보입니다. 나는이 체크 박스 코드가 있습니다PHP에서 적어도 하나의 체크 박스가 선택되어 있는지 확인하십시오.
<h1>_________</h1>
<p>Which records would you like to see?<br />
Enter as little or as many criteria as you want and then press Submit.</p>
<form method = "get" action = "http://www.its-a-secret.com/validation.php">
<div>
<span>
<label for = "lastname" id = "txtlabel">Last Name</label>
<input type = "text" name = "lastname" />
</span>
<span>
<label for = "firstname" id = "txtlabel">First Name</label>
<input type = "text" name = "firstname" />
</span>
<span>
<label for = "company" id = "txtlabel">Company</label>
<?php
session_start();
mysql_connect("______","_______","________");
mysql_select_db("____");
$sql = "SELECT DISTINCT company FROM _____";
$result = mysql_query($sql);
print "<select name = 'company' id = 'company'> \n";
print " <option></option> \n";
while ($row = mysql_fetch_array($result)) {
print " <option value='" . $row['company'] . "'>" . $row['company'] . "</option> \n";
}
print " </select> \n";
?>
</span>
<span id = "spanaccttype">
<label for = "accttype" id = "txtlabel">Account type</label>
<?php
mysql_connect("_____","_____","_______");
mysql_select_db("_____");
$sql = "SELECT DISTINCT accttype FROM _____";
$result = mysql_query($sql);
print "<select name = 'accttype' id = 'accttype'> \n";
print " <option></option> \n";
while ($row = mysql_fetch_array($result)) {
print " <option value='" . $row['accttype'] . "'>" . $row['accttype'] . "</option> \n";
}
print " </select> \n";
?>
</span>
<span id = "spanproductname">
<label for = "productname" id = "txtlabel">Product Name</label>
<?php
mysql_connect("______","______","______");
mysql_select_db("_____");
$sql = "SELECT DISTINCT productname FROM ______";
$result = mysql_query($sql);
print "<select name = 'productname' id = 'productname'> \n";
print " <option></option> \n";
while ($row = mysql_fetch_array($result)) {
print " <option value='" . $row['productname'] . "'>" . $row['productname'] . "</option> \n";
}
print " </select> \n";
?>
</span>
<span id = "spansharetype">
<label for = "sharetype" id = "txtlabel">Share Type</label>
<?php
mysql_connect("_____","_____","______");
mysql_select_db("_____");
$sql = "SELECT DISTINCT sharetype FROM _____";
$result = mysql_query($sql);
print "<select name = 'sharetype' id = 'sharetype'> \n";
print " <option></option> \n";
while ($row = mysql_fetch_array($result)) {
print " <option value='" . $row['sharetype'] . "'>" . $row['sharetype'] . "</option> \n";
}
print " </select> \n";
?>
</span>
<span id = "spanclosed">
<label for = "closed" id = "txtlabel">Closed?</label>
<?php
mysql_connect("_________","______","__");
mysql_select_db("____");
$sql = "SELECT DISTINCT closed FROM _____";
$result = mysql_query($sql);
print "<select name = 'closed' id = 'closed'> \n";
print " <option></option> \n";
while ($row = mysql_fetch_array($result)) {
print " <option value='" . $row['closed'] . "'>" . $row['closed'] . "</option> \n";
}
print " </select> \n";
?>
</span>
<span id = "spanvaluegreaterthan">
<label for = "valuegreaterthan" id = "txtlabel">Value Greater Than $</label>
<input type = "number" name = "valuegreaterthan" />
</span>
<br />
<span id = "spanwhatcolumnstoshowquestion">What columns would you like to show? (Note if none are checked none of the below will be shown.)</span>
<table id = "showwhichcolumns">
<tr>
<td><input type = "checkbox" id = "showcolumncompany" name = "showcolumncompany" value = "showcolumncompany" title = "Show column company" /><label for = "showcolumncompany" id = "check">Company</label></td>
</tr>
<tr>
<td><input type = "checkbox" id = "showcolumnaccountnumber" name = "showcolumnaccountnumber" value = "showcolumnaccountnumber" title = "Show column account number" /><label for = "showcolumnaccountnumber" id = "check">Account #</label></td>
</tr>
<tr>
<td><input type = "checkbox" id = "showcolumncontractdate" name = "showcolumncontractdate" value = "showcolumncontractdate" title = "Show column contract date" /><label for = "showcolumncontractdate" id = "check">Contract Date</label></td>
</tr>
<tr>
<td><input type = "checkbox" id = "showcolumnclosed" name = "showcolumnclosed" value = "showcolumnclosed" title = "Show column close" /><label for = "showcolumnclosed" id = "check">Closed?</label></td>
</tr>
<tr>
<td><input type = "checkbox" id = "showcolumndateclosed" name = "showcolumndateclosed" value = "showcolumndateclosed" /><label for = "showcolumndateclosed" id = "check">Date Closed</label></td>
</tr>
<tr>
<td><input type = "checkbox" id = "showcolumndob" name = "showcolumndob" value = "showcolumndob" /><label for = "showcolumndob" id = "check">DOB</label></td>
</tr>
<tr>
<td><input type = "checkbox" id = "showcolumnproductname" name = "showcolumnproductname" value = "showcolumnproductname" /><label for = "showcolumnproductname" id = "check">Product Name</label></td>
</tr>
<tr>
<td><input type = "checkbox" id = "showcolumncommissionpercent" name = "showcolumncommissionpercent" value = "showcolumncommissionpercent" /><label for = "showcolumncommissionpercent" id = "check">Commission %</label></td>
</tr>
<tr>
<td><input type = "checkbox" id = "showcolumncommissionpayoutpercent" name = "showcolumncommissionpayoutpercent" value = "showcolumncommissionpayoutpercent" /><label for = "showcolumncommissionpayoutpercent" id = "check">Commission Payout (%)</label></td>
</tr>
<tr>
<td><input type = "checkbox" id = "showcolumncommissionpayoutdollars" name = "showcolumncommissionpayoutdollars" value = "showcolumncommissionpayoutdollars" /><label for = "showcolumncommissionpayoutdollars" id = "check">Commission Payout ($)</label></td>
</tr>
<tr>
<td><input type = "checkbox" id = "showcolumntrailcomm" name = "showcolumntrailcomm" value = "showcolumntrailcomm" /><label for = "showcolumntrailcomm" id = "check">Trail Comm?</label></td>
</tr>
<tr>
<td><input type = "checkbox" id = "showcolumnguaranteepercent" name = "showcolumnguaranteepercent" value = "showcolumnguaranteepercent" /><label for = "showcolumnguaranteepercent" id = "check">Guarantee %</label></td>
</tr>
<tr>
<td><input type = "checkbox" id = "showcolumnaccounttype" name = "showcolumnaccounttype" value = "showcolumnaccounttype" title = "Show column account type" /><label for = "showcolumnaccounttype" id = "check">Account Type</label></td>
</table>
<p>
<input type = "submit" value = "Submit" id = "gobutton" />
</p>
형태가 페이지라는 validation.php에 제출하고이 해당 페이지에 대한 코드입니다 (I 거의 아직 아무것도 없다) :
이<?php
$lastname = $_REQUEST["lastname"];
$firstname = $_REQUEST["firstname"];
$company = $_REQUEST["company"];
$accttype = $_REQUEST["accttype"];
$productname = $_REQUEST["productname"];
$sharetype = $_REQUEST["sharetype"];
$closed = $_REQUEST["closed"];
$valuegreaterthan = $_REQUEST["valuegreaterthan"];
header("Location: http://www.its-a-secret/?lastname=" . htmlspecialchars($lastname) . "&firstname=" . htmlspecialchars($firstname) . "&company=" . htmlspecialchars($company));
?>
싶습니다에 HTML 특수 문자를 변경하지 말고 삭제하십시오. 사용자에게 말하여 대문자를 하나만 갖기를 원합니다. 만약 그들이 SQL을 사용하여 유효성을 검사하기를 원한다면 이름이나 성이 모두 자본이거나 그런 미친 짓이야. 또한 성 (姓)과 성 (姓)이 있으면 거기에 모든 공간이 있어야합니다. 적어도 하나의 확인란을 선택해야합니다. 또한 숫자 텍스트 상자에 숫자 인 양수가 있어야합니다.
이 기본적으로 검사 (검사) –
당신은 사용자가 자신이 HTML에 있던 체크 박스에 데이터를 제출 한 경우는 기본적으로 확인 코드 –
를 설명한다면 도움이 될 것이다. –