Jump to content

avinashd

New Members
  • Posts

    1
  • Joined

  • Last visited

Everything posted by avinashd

  1. I am new in php. i want to create a program with input fields as width, height etc. where user input their value and display output as total area, I already finished till here, but i also need a rectangle or div shape as entered input value(width and height). shape should be change according to input values, I tried but could not succeed, can someone please guide me how to do it? here it is my code, although it is very poor coding, still learning. <?php if(!isset($_POST['submit'])){ ?> <form method="post"action="<?php echo $_SERVER['PHP_SELF'];?>"> <h2>Please enter rectangle value</h2> <p>Enter width value <input type="text"name="w"/></p> <p>Enter height value <input type="text"name="h"/></p> <p><input type="submit"name="submit"value="Submit"/> <input type="reset"name="reset"value="Reset"/></p> </form> <?php }else{ $w=$_POST['w']; $h=$_POST['h']; if(empty($_POST['w'])|| empty($_POST['h'])){ echo"please enter value<br/>"; } elseif(!ctype_digit($w)|| (!ctype_digit($h))){ echo"value must be integer<br/>"; } else { $w=$_POST['w']; $h=$_POST['h']; } echo "Total area is ".calc($w,$h); } $w=0; $h=0; function calc($w,$h){ $area=$w*$h; if($w==$h){ echo"It is a square<br/>"; }else{ echo"It is a rectangle<br/>"; } return $area; } ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.