使用PHP中的GET和POST回应表单数据和操作

Actually I need to echoed the form and get the form data in the same php page or send to another php page,A pseudo code is prepared as i cannot post my original code here .

  <?php echo "<html><body>";
  if(isset($_POST['submit']))
{
    $name = $_POST['firstname'];
    echo "User Has submitted the form and entered this name : <b> $name </b>";
}
echo"<form action=$_SERVER['PHP_SELF']>
    First name:<br>
    <input type='text' name='firstname' value='John'><br>
    Last name:<br>
    <input type='text' name='lastname' value='Rambo'><br><br>
    <input type='submit' value='Submit'>
    </form></body></html>";
?>

The php page is call/loaded successfully loaded .The form is also working.But form action=$_SERVER['PHP_SELF'] is not working as well as the code below is also not working.

 if(isset($_POST['submit']))
{
    $name = $_POST['firstname'];
    echo "User Has submitted the form and entered this name : <b> $name </b>";
}

This is tested code. Similar to what your want.

Change $_SERVER['PHP_SELF'] to #

<?php
error_reporting(E_ERROR );
$first = '';
$last = '';
if (intval($_POST['sub'])){
  $first = $_POST['firstname'];
  $last = $_POST['lastname'];
}

echo <<<EOT
<html><head></head><body>
<form action="#" method="post">
    First name:<br>
    <input type='text' name='firstname' value="$first"><br>
    Last name:<br>
    <input type='text' name='lastname'  value="$last"><br><br>
    <input type='submit' value='Submit'/>
    <input type="hidden" name="sub" value=1/> 
    </form></body></html>
EOT;
?>