473,396 Members | 1,599 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Php $_post

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
5 1591
Markus
6,050 Expert 4TB
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
5,058 Expert 4TB
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
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
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
5,821 Expert 4TB
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

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

Similar topics

11
by: Adrian Parker | last post by:
Is it possible to click on a button, and not have it's value and name stored in _POST? I have this script with a button on it. When you click the button, the page posts to itself. The first...
4
by: Kevin | last post by:
I am having problems in my php code. I am relatively new to php but I know some basics. This is the problem: when i try to echo some information that is typed into form back to the screen i...
15
by: zorro | last post by:
greetings... I'm wondering what more advanced coders would think ot this: $_POST = clean($_POST); and now I can use POST directly: $sql= "select * from T1 where myvar='$_POST' " ;
7
by: Dynamo | last post by:
I am using values stored an $_POST array to display records from a table before asking the user if he is sure he wants to delete them. If the user confirms then the records are deleted. Without...
1
by: RDizzle | last post by:
okay. so all i am doing is changing a registration script that uses $_GET to a script that uses $_POST, but the validation script now returns NULL values for all posted vars. What's the deal? ...
6
by: comp.lang.php | last post by:
I have no idea why this is happening and I need someone to explain this to me at the simplest level absolutely possible (pretend I'm a 10-year old and explain it that way, please!) This class...
5
by: comp.lang.php | last post by:
// NEW 11/27/2006: FINALLY, IF YOU ADDED OR DELETED OR DID ANY KIND OF FORM ACTION SUCCESSFULLY, DON'T RE-DISPLAY THE NEW EXPENSE ITEMS VIA $_POST if ($_POST && (!is_array($leaseObj->errorArray)...
3
by: scabman | last post by:
Working on upgrading a site and after moving everything onto a test server (localhost) things started to get real buggy. Went through and checked all my links and everything comes up fine, but it...
12
by: Todd Michels | last post by:
Hi all, I am trying to send data from a form and insert it into a MSSQL DB. When I submit the data I get: Warning: mssql_query() : message: The name "Todd" is not permitted in this context....
5
Tarantulus
by: Tarantulus | last post by:
Hi, ok, quick description of the problem, I'm trying to reference the postdata from some checkboxes. Unfortunately the checkboxes are dynamically generated therefore I don't know how many there...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.