?
Solved

getting http posts

Posted on 2007-11-22
1
Medium Priority
?
266 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 20

Accepted Solution

by:
steelseth12 earned 2000 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

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

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…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

800 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