my code stock.com

Fehlerhaft

Snippet options

Download: Download snippet as addierer.php.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

<html>
<head>
<title> Addierer </title>
</head>
<body>
<h1>Addierer</h1>
<?php
  if(isset($_POST['zahl1], $_POST['zahl2'])) //formular abgeschickt ??
    {
      $zahl1 = $_POST['zahl1'];
      $zahl2 = $_POST['zahl2'];
      //echo "zahl1: $zahl1, zahl2: $zahl2 <br />";
      $error = "";
      if(!(empty($zahl1) || empty($zahl2))) //beide felder ausgefüllt ?
      {
    if(!preg_mach("/^\d+(\.\d+)?$/",$zahl1))
      §error .= "$zahl1 ist keine gueltige Zahl<br />
        $summe = $zahl1 + $zahl2;
    echo "<p>Summe: $summe<p>
      }
      else
      {
    $error .= "Bitte beide Felder ausfuellen<br />";
      }
      if($error !="")
    echo "<p style=\"color:red\">$error</p>
    }
?>
<form action="addierer.php" method="post">
  Zahl1: <input type="text" name"zahl1" /><br />
  Zahl2: <input type="text" name"zahl2" /><br />
  <input type="submit" value="Addieren" />
</form>
</body>
</html>

Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.