Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

getting http posts

Posted on 2007-11-22
1
Medium Priority
?
272 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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 …
Suggested Courses

610 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