繁体   English   中英

将表单数据检索到php处理器中

[英]Retrieving form data into a php processor

我在理解如何使foreach函数正常工作时遇到问题。 我有一个使用复选框的表格。 我尝试将它们作为复选框数组加载,但是无法获取foreach函数对我有用。 我不太了解所有这些。 让我快速发布表单数据:

<form method="post" action="interests.php" name="interests">

<table width="500" cellspacing="3" cellpadding="3" bgcolor="#FF80FF" bordercolor="#800000">

<tr>
    <td><input type="checkbox" name="check1" value="1"></td>
    <td><input type="checkbox" name="check2" value="2"></td>
    <td><input type="checkbox" name="check3" value="3"></td>
    <td><input type="checkbox" name="check4" value="4"></td>    
</tr>
<tr>
    <td><input type="checkbox" name="check5" value="5"></td>
    <td><input type="checkbox" name="check6" value="6"></td>
    <td><input type="checkbox" name="check7" value="7"></td>
    <td><input type="checkbox" name="check8" value="8"></td>
</tr>
<tr>
    <td colspan="2"><input type="submit"></td>
    <td colspan="2"><input type="reset"></td>
</tr>
</table>

</form>

到目前为止,这是我的PHP处理器..:

<?php
for(x=1;x>8;x++){
    $loop=

echo 'Your interests have been updated into the database, and those files will now</br>';
echo 'begin showing up in the files area on your files sections.';
?>

我知道不多,因为我被困住了。 我在敲头。 我需要对此进行解析,并检查是否填充了值,以便可以将数据输入数据库。 似乎很简单,但是由于某种原因我无法理解!

编辑后,我建议给所有复选框name='check[]' ,在您的php代码中,您将获得在$_POST['check']中检查的所有输入值,而无需尝试手动进行操作,此代码将回显所有检查的值:

<?php
if(!empty($_POST['check'])) {
    foreach($_POST['check'] as $check) {
            echo $check.'<br/>'; //echo checked value
    }
}
?>

第一个答案:

使用PHP使用最小化的HTML代码modulus$a % $b的弹性模量剩余$a除以$b )来显示<tr>每4个输入之前元件

尝试这个 :

<form method="post" action="interests.php" name="interests">

<table width="500" cellspacing="3" cellpadding="3" bgcolor="#FF80FF" bordercolor="#800000">

<?php
for($i=1;$i<=8;$i++){

  if (($i-1)%4==0) echo "<tr>";
  echo "<td><input type='checkbox' name='check$i' value='$i'/></td>";
}
?>
    <tr>
    <td colspan="2"><input type="submit"></td>
    <td colspan="2"><input type="reset"></td>
</tr>
</table>

</form>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM