$_POST not always set?

From: Adrian Parker (adrian.parker_at_NOSPAMsympatico.ca)
Date: 04/29/04


Date: Thu, 29 Apr 2004 15:28:54 -0400

Is it possible to click on a button, and not have it's value and name stored
in _POST?

I have this script with a button on it. When you click the button, the page
posts to itself. The first time you click this Save Changes button, _POST
is empty. After clicking the button, and the page is loaded again, if you
click Save Changes once more the _POST is properly set. What's up with
that?

 $studentCode; // Will hold the current student code, if applicable

...

 foreach(array_keys($_POST) as $key)
 {
   $$key = $_POST[$key];
   print "$key is ${$key}<br />";
  echo "It is: " . $_POST["Submit"] . "<br>";
 }

 if ($_POST["Submit"] == "Add Student") // Save button was hit
  addRecord();
 elseif ($_POST["Submit"] == "Save Changes") // Save changes button was hit
  updateStudent();
  echo "We're saving changes<br>";
 elseif ($_GET["action"] != "add")
  getOldData($record);

 echo "<table summary=\"\" cellpadding=\"5\">";

 function printLabelCell()
 {
  echo "\n<tr><td align=\"right\">";
 }

 if (isset($_GET["studentCode"]))
  $studentCode = $_GET["studentCode"];
 elseif (isset($_POST["studentCode"]))
  $studentCode = $_POST["studentCode"];

 if ($studentCode != "")
  $postType = "post?studentCode=" . $studentCode;
 else
  $postType = "post";

   echo '<form action="addEditStudent.php" method="' . $postType . '">';

// ... print controls in the cells ...

 echo "<tr><td colspan=\"2\" align=\"center\">";

 echo '<br>';

 if ($_GET["action"] == "add" or isset($_POST["firstName"]))
    echo '<input type="Submit" name="Submit" value="Add Student">&nbsp;
&nbsp; &nbsp; ';
 else
  echo '<input type="Submit" name="Submit" value="Save Changes">';

 echo '&nbsp; &nbsp; &nbsp; <input type="Reset" name="Reset" value="Clear
Data"><br><br>';

 echo "</td></tr></table>";

  echo "</form>";

function DisplayTextbox($vname, $size, $value)
{
    echo "</td><td><Input type=\"text\" name = \"" . $vname . "\" Size = \""
. $size . "\" value=\"" . $value . "\"></td></tr>";
}

 mysql_close($link);

...

<Ade

-- 
Adrian Parker.  Ordained priest.  <adrian.parker@sympatico.ca>
"A society that views graphic violence as entertainment ...should not be
surprised when senseless violence shatters the dreams of it's youngest and
brightest..."  - Ensign (March 2004)

Quantcast