我的表格有三个部分;级别1,级别2和级别3.这些部分中的每一个都包含四个文本区域和一个单选按钮组,每个文本区域旁边都有单选按钮:
<form action="" method="post" name="form" id="form" onSubmit="return validate();">
<table width="123%" border="0" cellpadding="5">
<th colspan="6">
<div align="center"><strong>Level 1</strong></div> </th>
<tr>
<td valign="top"><strong>Pathway</strong></td>
<td colspan="2"><strong>Blocking or Accepting Comment</strong></td>
<td valign="top"><strong>Appropriate</strong></td>
</tr>
<tr>
<td width="26%" valign="top"><strong>Pathway 1:</strong> No action - See again</td>
<td colspan="2"><div class="required">
<textarea name="l1_p1_comment" id="l1_p1_comment" cols="35" rows="5"></textarea>
</div></td>
<td width="18%" valign="top"><p>
<input type="radio" name="l1_allowed" value="1" id="l1_allowed_0" />
</td>
</tr>
<tr>
<td valign="top"><strong>Pathway 2:</strong> See again</td>
<td colspan="2"><div class="required">
<textarea name="l1_p2_comment" id="l1_p2_comment" cols="35" rows="5"></textarea>
</div></td>
<td valign="top"><input type="radio" name="l1_allowed" value="1" id="l1_allowed_1" /></td>
</tr>
<tr>
<td valign="top"><strong>Pathway 3:</strong> Refer to ED</td>
<td colspan="2"><div class="required">
<textarea name="l1_p3_comment" id="l1_p3_comment" cols="35" rows="5"></textarea>
</div></td>
<td valign="top"><input type="radio" name="l1_allowed" value="1" id="l1_allowed_2" /></td>
</tr>
<tr>
<td valign="top"><strong>Pathway 4:</strong> Refer to Specialist</td>
<td colspan="2"><div class="required">
<textarea name="l1_p4_comment" id="l1_p4_comment" cols="35" rows="5"></textarea>
</div></td>
<td valign="top"><input type="radio" name="l1_allowed" value="1" id="l1_allowed_3" /></td>
</tr>
<tr>
<td valign="top"> </td>
<td colspan="2"> </td>
<td> </td>
</tr>
<th colspan="6">
<div align="center"><strong>Level 2</strong></div> </th>
<tr>
<td valign="top"><strong>Pathway</strong></td>
<td colspan="2"><strong>Blocking or Accepting Comment</strong></td>
<td valign="top"><strong>Appropriate</strong></td>
</tr>
<tr>
<td width="26%" valign="top"><strong>Pathway 1:</strong> No action - See again</td>
<td colspan="2"><div class="required">
<textarea name="l2_p1_comment" id="l2_p1_comment" cols="35" rows="5"></textarea>
</div></td>
<td width="18%" valign="top"><p>
<input type="radio" name="l2_allowed" value="1" id="l2_allowed_0" />
</td>
</tr>
<tr>
<td valign="top"><strong>Pathway 2:</strong> See again</td>
<td colspan="2"><div class="required">
<textarea name="l2_p2_comment" id="l2_p2_comment" cols="35" rows="5"></textarea>
</div></td>
<td valign="top"><input type="radio" name="l2_allowed" value="1" id="l2_allowed_1" /></td>
</tr>
<tr>
<td valign="top"><strong>Pathway 3:</strong> Refer to ED</td>
<td colspan="2"><div class="required">
<textarea name="l2_p3_comment" id="l2_p3_comment" cols="35" rows="5"></textarea>
</div></td>
<td valign="top"><input type="radio" name="l2_allowed" value="1" id="l2_allowed_2" /></td>
</tr>
<tr>
<td valign="top"><strong>Pathway 4:</strong> Refer to Specialist</td>
<td colspan="2"><div class="required">
<textarea name="l2_p4_comment" id="l2_p4_comment" cols="35" rows="5"></textarea>
</div></td>
<td valign="top"><input type="radio" name="l2_allowed" value="1" id="l2_allowed_3" /></td>
</tr>
<tr>
<td valign="top"> </td>
<td colspan="2"> </td>
<td> </td>
</tr>
<th colspan="6">
<div align="center"><strong>Level 3</strong></div> </th>
<tr>
<td valign="top"><strong>Pathway</strong></td>
<td colspan="2"><strong>Blocking or Accepting Comment</strong></td>
<td valign="top"><strong>Appropriate</strong></td>
</tr>
<tr>
<td width="26%" valign="top"><strong>Pathway 1:</strong> No action - See again</td>
<td colspan="2"><div class="required">
<textarea name="l3_p1_comment" id="l3_p1_comment" cols="35" rows="5"></textarea>
</div></td>
<td width="18%" valign="top"><p>
<input type="radio" name="l3_allowed" value="1" id="l3_allowed_0" />
</td>
</tr>
<tr>
<td valign="top"><strong>Pathway 2:</strong> See again</td>
<td colspan="2"><div class="required">
<textarea name="l3_p2_comment" id="l3_p2_comment" cols="35" rows="5"></textarea>
</div></td>
<td valign="top"><input type="radio" name="l3_allowed" value="1" id="l3_allowed_1" /></td>
</tr>
<tr>
<td valign="top"><strong>Pathway 3:</strong> Refer to ED</td>
<td colspan="2"><div class="required">
<textarea name="l3_p3_comment" id="l3_p3_comment" cols="35" rows="5"></textarea>
</div></td>
<td valign="top"><input type="radio" name="l3_allowed" value="1" id="l3_allowed_2" /></td>
</tr>
<tr>
<td valign="top"><strong>Pathway 4:</strong> Refer to Specialist</td>
<td colspan="2"><div class="required">
<textarea name="l3_p4_comment" id="l3_p4_comment" cols="35" rows="5"></textarea>
</div></td>
<td valign="top"><input type="radio" name="l3_allowed" value="1" id="l3_allowed_3" /></td>
</tr>
<tr>
<td> </td>
<td colspan="2"><input type="submit" name="submit" id="submit" value="Create Pathways for All Levels" /></td>
<td> </td>
</tr>
</table>
</form>
在提交时,有一个多次插入:
$l1_p1_comment = $_POST['l1_p1_comment'];
$l1_p2_comment = $_POST['l1_p2_comment'];
$l1_p3_comment = $_POST['l1_p3_comment'];
$l1_p4_comment = $_POST['l1_p4_comment'];
$l2_p1_comment = $_POST['l2_p1_comment'];
$l2_p2_comment = $_POST['l2_p2_comment'];
$l2_p3_comment = $_POST['l2_p3_comment'];
$l2_p4_comment = $_POST['l2_p4_comment'];
$l3_p1_comment = $_POST['l3_p1_comment'];
$l3_p2_comment = $_POST['l3_p2_comment'];
$l3_p3_comment = $_POST['l3_p3_comment'];
$l3_p4_comment = $_POST['l3_p4_comment'];
$l1_allowed = $_POST['l1_allowed'];
$l2_allowed = $_POST['l2_allowed'];
$l3_allowed = $_POST['l3_allowed'];
if(isset($_POST['submit'])){
$query =
"INSERT INTO pathway
(pathway_pk, case_fk, level, pathway_allowed, comment, created, created_by)
VALUES
('', '$case_fk', '1', '$l1_allowed', '$l1_p1_comment', NOW(), '$author_pk'),
('', '$case_fk', '1', '$l1_allowed', '$l1_p2_comment', NOW(), '$author_pk'),
('', '$case_fk', '1', '$l1_allowed', '$l1_p3_comment', NOW(), '$author_pk'),
('', '$case_fk', '1', '$l1_allowed', '$l1_p4_comment', NOW(), '$author_pk'),
('', '$case_fk', '2', '$l2_allowed', '$l2_p1_comment', NOW(), '$author_pk'),
('', '$case_fk', '2', '$l2_allowed', '$l2_p2_comment', NOW(), '$author_pk'),
('', '$case_fk', '2', '$l2_allowed', '$l2_p3_comment', NOW(), '$author_pk'),
('', '$case_fk', '2', '$l2_allowed', '$l2_p4_comment', NOW(), '$author_pk'),
('', '$case_fk', '3', '$l3_allowed', '$l3_p1_comment', NOW(), '$author_pk'),
('', '$case_fk', '3', '$l3_allowed', '$l3_p2_comment', NOW(), '$author_pk'),
('', '$case_fk', '3', '$l3_allowed', '$l3_p3_comment', NOW(), '$author_pk'),
('', '$case_fk', '3', '$l3_allowed', '$l3_p4_comment', NOW(), '$author_pk')
";
$result = mysql_query($query, $connection) or die(mysql_error());
现在,我想让三个部分(级别1,级别2和级别3)中的每一个的无线电组为选定的无线电提交值“1”(即允许),并且每个组中的其他无线电提交'0'来自:
$l1_allowed = $_POST['l1_allowed'];
$l2_allowed = $_POST['l2_allowed'];
$l3_allowed = $_POST['l3_allowed'];
关于我如何做到这一点的任何建议?
答案 0 :(得分:0)
首先,escape your inputs correctly。
然后将代码处理表单的数据放入单独的页面,如submit_action.php。
并尽量避免使用if(isset($_POST['submit'])){
。代替:
if(isset($_POST['input1'])) {
$input1 = ($_POST['input1']);
} else {
$input1 = "None";
}
if(isset($_POST['input2'])) {
$input1 = ($_POST['input2']);
} else {
$input1 = "None";
}
<form action="submit_action.php" method="post" name="aFormName" id="form">
然后,在你的INSERT中:
$query="INSERT INTO $tbl_name(col1, col2)VALUES('$input1', '$input2')";
你指的是提交什么,反正呢?我看到你的问题中没有页面链接。什么是validate()?
答案 1 :(得分:0)
好的,我认为这对于多个插入来说太难了,所以将这三个区域拆分成单独的形式并使用:
$l1_allowed = intval($_POST['l1_allowed']);
$l2_allowed = intval($_POST['l2_allowed']);
$l3_allowed = intval($_POST['l3_allowed']);
if(isset($_POST['pathways_level_1'])){
$pathway_comment_l1 = array();
foreach($_POST['comment_l1'] as $comment_l1) {
$pathway_comment_l1[]= mysql_real_escape_string($comment_l1);
}
for($i=0, $count = count($pathway_comment_l1);$i<$count;$i++) {
$comment_l1 = $pathway_comment_l1[$i];
$query_level_1 = sprintf(
"INSERT INTO pathway (
pathway_pk,
case_fk,
level,
pathway_allowed,
comment
) VALUES (
'',
'$case_pk',
'1',
'%s',
'$comment_l1')", $l1_allowed === $i ? 'y' : 'n');
$result_level_1 = mysql_query($query_level_1, $connection) or die(mysql_error());
}
if($result_level_1){
$message = "- The pathways for level 1 have been created.";
}
}
?>