Hi I'm trying to figure out how to do a simple calculator code. What I want to end up with is something where users enter two figures hit a button and then the result is displayed as out put. For example, the calculation I want it to do is: x divided by y mulitplied by 1000 How do I do this??
If you have php on your server you can do it very easily. <form action="" method="POST"> Enter X: <input type="text" name="x"> Enter Y: <input type="text" name="y"> <input type="submit" name="submit" value="Calculate"> </form> <?PHP if(isset($_POST['submit'])){ $x = $_POST['x']; $y = $_POST['y']; $final = ($x/$y)*1000; echo $final; } ?> Code (markup):
When i click calculate now it goes to load a new page and then says The page cannot be displayed? This is what I have so far: <form action="<?PHP echo $PHP_SELF; ?>" method="POST"> Enter X: <input type="text" name="x"> Enter Y: <input type="text" name="y"> <input type="submit" name="submit" value="Calculate"> </form> <?PHP if(isset($_POST['submit'])){ $x = $_POST['x']; $y = $_POST['y']; $final = ($x/$y)*1000; echo $final; } ?>
Hmm. I just tested it and it works perfectly on my server. Can you make a phpinfo file? Make a file and put this as the only content in it. Upload it and then load that page. <?PHP phpinfo(); ?> Code (markup):
Ok, I think I know why it's not working for me. I just did it in notepad and was opening it in explorer from my hard drive. I haven't put it on a server or anything.