[英]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.