Solved

getting http posts

Posted on 2007-11-22
1
248 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Echo vs ?><?php  html code 4 47
nagios 4 php error after installation 6 79
simplest php form 3 64
myqsl update statement on phpMyAdmin 8 22
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 …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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.

864 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

22 Experts available now in Live!

Get 1:1 Help Now