PHP Beispiele und Übungen: Code 
    <?php
$titel = "PHP Formularverarbeitung";
$untertitel = "Unterschied POST und GET";
$pagename = basename($_SERVER["PHP_SELF"]);
$strbtnlblmult = "Multiplizieren";
?>
<?php include 'incdoctype.php'?>
<html>
  <head>
    <?php include 'incheader.php'?>
    <title><?php echo "$titel: $untertitel"?></title>
  </head>
  <body>
    <div class="main">
      <h1><?php echo "$titel: $untertitel"?></h1>
      <h2>Formular
</h2>
      Post: 
      
<form action="<?php echo $pagename ?>" method="post">
        
<input type="Text" name="frmfldtext1" /> * 
<input type="text" name="frmfldtext2" />
        <input type="submit" value="<?php echo $strbtnlblmult ?>" name="btnsubmit">
      
</form>
      Get: 
      
<form action="<?php echo $pagename ?>" method="get">
        
<input type="Text" name="frmfldtext1" /> * 
<input type="text" name="frmfldtext2" />
        <input type="submit" value="<?php echo $strbtnlblmult ?>" name="btnsubmit" />
      
</form>
      <?php
      if ($_POST["btnsubmit"] == $strbtnlblmult) {
        echo "<p>" . $_POST["frmfldtext1"] 
          . " * " . $_POST["frmfldtext2"] . " = "  
          . $_POST["frmfldtext1"] * $_POST["frmfldtext2"] 
          . "</p>\n";
        //ohne POST
        echo "<p>\$_REQUEST statt \$_POST: "
          . $_REQUEST["frmfldtext1"] * $_REQUEST["frmfldtext2"] 
          . "</p>\n";
      }
      if ($_GET["btnsubmit"] == $strbtnlblmult) {
        echo "<p>" . $_GET["frmfldtext1"]
          . " * " . $_GET["frmfldtext2"] . " = "
          . $_GET["frmfldtext1"] * $_GET["frmfldtext2"]
          . "</p>\n";
        //ohne GET
        echo "<p>\$_REQUEST statt \$_GET: "
          . $_REQUEST["frmfldtext1"] * $_REQUEST["frmfldtext2"]
          . "</p>\n";
      }    ?>
      <?php include 'incfooter.php'?>
    </div>
  </body>
</html>
    
	  Demo   
    
  
   Zurück zur Liste mit PHP-Beispielen
   Zurück zu www.ecotronics.ch
   Impressum und Datenschutzerklärung