By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,304 Members | 1,254 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,304 IT Pros & Developers. It's quick & easy.

Php $_post

P: 4
I have this code:
Expand|Select|Wrap|Line Numbers
  1. $g = 1;
  2.         echo $checkListCount;
  3.         while($g <= $checkListCount){
  4.  
  5.             $fg = 'sdl'.$g;
  6.  
  7.             echo $_POST[$fg];
  8.  
  9.             ++$g;           
  10.        }
  11.  
The question is, why won't it work?
It doesn't give out any error but it doesn't do what it should?
And a there really are values for $_POST['sdl1'],$_POST['sdl2'],$_POST['sdl3']...

I think the problem's with this:
echo $_POST[$fg];

Any help will be very much appreciated.
Oct 11 '08 #1
Share this Question
Share on Google+
5 Replies


Markus
Expert 5K+
P: 6,050
What does happen? What doesn't happen? What is *supposed* to happen?
No errors?

Do a print_r() on $_POST and see what's actually in there.

Markus
Oct 11 '08 #2

Atli
Expert 5K+
P: 5,058
Hi.

The $_POST super-global gets it's values from HTML forms (usually).
So, how does the form that supplies the data for you script look like?
Oct 11 '08 #3

P: 4
What I want to happen sir is to make the value for $_POST[' '] dynamic.

For example:

If i have such data from a form as $_POST['a1'], $_POST['a2'], $_POST['a3'], so on..

This:
Expand|Select|Wrap|Line Numbers
  1.  $g = 1;
  2.          echo $checkListCount;
  3.          while($g <= $checkListCount){
  4.  
  5.              $fg = 'a'.$g;
  6.  
  7.              echo $_POST[$fg];
  8.  
  9.              ++$g;           
  10.          }
  11.  
will output all the values of $_POST['a1'], $_POST['a2'], $_POST['a3'], so on..

thanks for the reply
Oct 12 '08 #4

P: 4
Hi.

The $_POST super-global gets it's values from HTML forms (usually).
So, how does the form that supplies the data for you script look like?
The form is this way:
Expand|Select|Wrap|Line Numbers
  1. <form action="'.$_SERVER['PHP_SELF'].'" method="post">
  2. $c=1;
  3.  while($row = mysql_fetch_array($list)){
  4.  
  5.                                         $at = 'syear'.$c;
  6.                                         $bt = 'semester'.$c;
  7.                                         $ct = 'colcov'.$c;
  8.                                         $dt = 'col2bcov'.$c;
  9.                                         $et = 'sdl'.$c;
  10.  
  11. echo '<table align="center" width="500" cellpadding="0" cellspacing="0">
  12. <tr  style="background-color:#dddddd;">
  13. <td align="center" class="style9"><input type="text" name="'.$at.'" value='. $row['syear'].'></td>
  14. <td align="center" class="style9"><input type="text" name="'.$bt.'" value='. $row['semester'].'></td>
  15. <td align="center" class="style9"><input type="text" name="'.$ct.'" value='. $row['colcov'].'></td>
  16. <td align="center" class="style9"><input type="text" name="'.$dt.'" value='. $row['col2bcov'].'></td>
  17. <td align="center" class="style9"><input type="text" name="'.$et.'" value='. $row['sdl'].'></td>
  18. </tr>
  19. </table>';
  20.  
  21.  
  22. echo '<table align="center" width="500" cellpadding="0" cellspacing="0">
  23.     <tr style="background-color:#333333;">
  24.     <td align="right">&nbsp;</td>
  25.     <td align="left"><input type="submit" name="submitEdit" value="Save"></td>
  26.         <td align="right"><input type="reset" value="Reset"></td>
  27.         </tr>
Oct 12 '08 #5

pbmods
Expert 5K+
P: 5,821
Heya, Clemton.

You're making this way too complicated. Name your inputs with '[]' at the end, and PHP will create an array inside of $_POST:

Expand|Select|Wrap|Line Numbers
  1. <input ... name="color[]" />
  2. <input ... name="color[]" />
  3.  
Expand|Select|Wrap|Line Numbers
  1. foreach( $_POST['color'] as $idx => $val ) ...
  2.  
http://php.net/variables.external
Oct 12 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.