Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting data from $_POST

Status
Not open for further replies.

lem72

Programmer
Jun 24, 2005
6
CA
help!

I want to do a while loop using $_POST. To extract data for example I want to do something like:

while ($i < sizeof($_POST)){

print $_POST[$i];
$I++;
};

Is this possible or something like this? I want to echo each of the contents of the $_POST without knowing what the actual value is called from the form.

Cheers,
Greg
 
No, the $_POST array indicies are not numbers. What you want to do is one of the following:
Code:
print_r($_POST);
Code:
var_dump($_POST);
Code:
foreach ($_POST as $key=>$val)
  echo $key . '=' . $val . '<br>';
There are probably a few other methods to do this also.

Ken
 
The 3rd option:

foreach ($_POST as $key=>$val)
echo $key . '=' . $val . '<br>';

Worsk almost perfectly, it replaces the .'s with _'s is there a way of getting around this? as they are email addresses where they can look like

greg.harrison@gmail.com and that shows up as: greg_harrison@gmail_com, i see i could do a str_replace but that would replace all the _'s with .'s so if you had an email that was:

Greg_harrison@gmail.com then it would replace the actual needed _.

Thank you so much for the helpo much appreciated!
 
It does nothing of the sort. If it prints underscores ( _ ) then those are in you data. What does print_r($_POST) say is in you data?

Ken
 
Do you use AIM, or MSN? I could show you the actual script if you wanted.

it changes:

<input name="carol@houseoffriendship.ca" type="checkbox" id="mailto:whatever"
value="checkbox" checked>
carol@houseoffriendship.ca<br><input name="words@best-view.com" type="checkbox" id="mailto:whatever"
value="checkbox" checked>
words@best-view.com<br><input name="dov.bercovici@acadiau.ca" type="checkbox" id="mailto:whatever"
value="checkbox" checked>

into:

Array ( [carol@houseoffriendship_ca] => checkbox [words@best-view_com] => checkbox [dov_bercovici@acadiau_ca] => checkbox
 
ps my aim = gharrison72, msn = lem72@hotmail.com

Cheers,
Greg
 
No, I don't use IM's

That's the first time I've seen that happen.

Try redoing your input lines to something like
Code:
<input name=checkbox[] value="carol@houseoffriendship.ca" type="checkbox" id="mailto:whatever" checked>
Then you would have an array called "checkbox" in $_POST with the values being the email addresses.

Ken
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top