dataValid.php - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of dataValid.php.php

  1. <?php
  2.     $valid=true;
  3.  
  4.     if (empty($_POST["nickname"])){
  5.         $valid=false;
  6.     }
  7.  
  8.     if (empty($_POST["height"])){
  9.         $valid=false;
  10.     }
  11.     elseif ($_POST["height"]<0 || $_POST["height"]>250){
  12.         $valid=false;
  13.     }
  14.  
  15.     if (empty($_POST["weight"])){
  16.         $valid=false;
  17.     }
  18.     elseif ($_POST["weight"]<0 || $_POST["weight"]>250){
  19.         $valid=false;
  20.     }
  21.  
  22.     if ($valid){
  23.         $bmi=$_POST["weight"]/(($_POST["height"]/100)**2);
  24.         echo "{$_POST["nickname"]}, your BMI is {$bmi}";
  25.     }
  26.     else{
  27.         echo "Invalid";
  28.     }
  29.  
  30.     if (count($_POST["teacher"])==0){
  31.         echo "怎會咁多老師都沒有一個是你欣賞的!"
  32.     }
  33.     else {
  34.         foreach ($i as $_POST["teacher"]){
  35.             echo "I like {$i} <br>";
  36.         }
  37.     }
  38. ?>
File Description
  • dataValid.php
  • PHP Code
  • 15 Apr-2024
  • 788 Bytes
You can Share it: