Solved

getting http posts

Posted on 2007-11-22
1
251 Views
Last Modified: 2008-02-07
when i load a form, i'm taking posts from a previous form using the following code

foreach ($_POST as $id) {
      
   preg_match('/^(\d+)(\w)$/', $id, $m);
   $elems[$m[1]] = $m[2];
}



on the current for, i want it to call its self using php_self and validate that the user has entered in some textboxes, this seems to cause a conflict as when i put

while (list($name,$value) = each($_POST)){
$$name = $value;
if ($value == ""){
      
     $variableName = $name."error";
     $$variableName = true;
        $overallerror = true;
}
}

after the code the post array is empty, does anybody have any suggestions?
0
Comment
Question by:markmchugh
1 Comment
 
LVL 20

Accepted Solution

by:
steelseth12 earned 500 total points
ID: 20333307
The internal pointer of the array advances as you loop through $_POST with the foreach function
The each() function does NOT reset the internal pointer
so after the foreach finishes you need to call

foreach ($_POST as $id) {
     
   preg_match('/^(\d+)(\w)$/', $id, $m);
   $elems[$m[1]] = $m[2];
}

reset($_POST);

or simply use foreach for your second loop that reset the pointer

foreach($_POST as $name=>$value) {
$$name = $value;
if ($value == ""){
     
     $variableName = $name."error";
     $$variableName = true;
        $overallerror = true;
}
}

0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question