phpで電卓を作っています。
画面と内部処理と2ファイル構成で実現させようとしていますが、
POST(ation先は別ファイル)で処理側のファイルで処理させた後、計算結果を画面に戻す方法が分かりません。
・calculator.php
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script> <title>電卓</title> <link rel="stylesheet" type="text/css" href="/css/app.css"> </head> <body> <form action="calculate.php" method="POST"> <input type="text" name="value1" id="value1" size="10" maxlengh="10" > <select name="symbol"> <option value=""></option> <option value="+">+</option> <option value="-">-</option> </select> <input type="text" name="value2" id="value2" size="10" maxlengh="10" > = ★★★//"="ボタンを押した後、calculate.phpで計算した結果をvalue=""に設定したい <input type="text" name="result" id="result" value="" size="10" maxlengh="10" > <table border="0"> <tr> <td><button type="button" value="1">1</button></td> <td><button type="button" value="2">2</button></td> <td><button type="button" value="3">3</button></td> </tr> <tr> <td><button type="button" value="4">4</button></td> <td><button type="button" value="5">5</button></td> <td><button type="button" value="6">6</button></td> </tr> <tr> <td><button type="button" value="7">7</button></td> <td><button type="button" value="8">8</button></td> <td><button type="button" value="9">9</button></td> </tr> <tr> <td></td> <td><button value="0">0</button></td> <td><input type="submit" value="="></td> </tr> </table> </form> </body> <script> $('button').click(function() { val = $(this).val(); if( !$("#value1").val() ) { $("#value1").val(val); }else{ $("#value2").val(val); } }) </script> </html>
・calculate.php
<?php $value1 = $_POST['value1']; $symbol = $_POST['symbol']; $value2 = $_POST['value2']; $result=""; if(is_numeric($value1)&&is_numeric($value2)){ switch ($symbol) { case '+': $result = $value1 + $value2; break; case '−': $result = $value1 - $value2; break; } } //この後の書き方が分からない ?>
基礎的なことだと思うのですが
教えていただければ幸いです。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/04/02 06:05
2020/04/02 06:10
2020/04/02 07:45
2020/04/02 08:16
2020/04/07 06:23