Solved

getting http posts

Posted on 2007-11-22
1
241 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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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.

763 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now