Show Post

When working with forms, it can be very useful to see what the post values are. The php script can access everything that was on the form. The post variables are in an array that can be displayed using a foreach loop.

<?php
// displays each post variable
echo 'POST<BR>';
  foreach($_POST as $id=>$value) {
    echo $id.' '.$value.'<BR>';
  }
?>

The foreach loop is especially designed for looping through an array. While you may be accustomed to programming languages where the index to an array is always an integer, in php the index may be a string. For example in the patient information form the elements of the array $_POST include $_POST['firstName']="Joe" and $_POST['month']=1;

To use a foreach loop you give an array and then the variable for the index or key, and the variable for the value. The statement above can be read, "For each POST as id points to value."


INDEX, Introduction, Form validation, Show Post variables
Next lesson: SessionsMAIN INDEX
EXAMPLES INDEX

Copyright © Zebra0.com
All rights reserved worldwide.

 
 

Show Post variables