Retrieving form data into a php processor -


i having problem understanding how make foreach function work. have form, uses check boxes. tried loading them array of check boxes, couldn't foreach function work me. don't understand of this. let me post form data real quick:

<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> 

here php processor far..:

<?php for(x=1;x>8;x++){     $loop=  echo 'your interests have been updated database, , files now</br>'; echo 'begin showing in files area on files sections.'; ?> 

i know, not much, because stuck. banging head. need parse out, , check values filled, can input data database. seems simple enough, reason cant it!

after edit , suggest give checkbox name='check[]' , in php code values of inputs checked in $_post['check'] without trying manually,this code echo checked values :

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

first answer :

to minimize html code using php use modulus ($a % $b modulus remainder of $a divided $b) show <tr> element before every 4 inputs

try :

<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> 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -