PHPとHTMLで簡単な計算機をつくりました。このようなコードです。
lang
1<html> 2<head> 3<title>PHP 計算機</title> 4</head> 5 6<body> 7<h1>計算機</h1> 8<form method="post" action="index.php"> 9test1:<input type="text" name="test1"><br> 10test2:<input type="text" name="test2"><br> 11attribute:<input type="text" name="attribute"><br> 12Result:<input type"text" name="result"><br> 13<input type="submit" name="submit" value="submit"> 14 15</form> 16</center> 17</body> 18</html> 19 20<?php 21if(isset($_POST['submit'])) { 22 $test1=$_POST['test1']; 23 $test2=$_POST['test2']; 24 $attribute=$_POST['attribute']; 25 26 if($test1=='') { 27 echo "<script>alert('test1を入力してください')</script>"; 28 exit(); 29 } 30 31 if($test2=='') { 32 echo "<script>alert('test2を入力してください')</script>"; 33 exit(); 34 } 35 36 if($attribute=='+') { 37 echo "答えは: " , $test1+$test2; 38 exit(); 39 } 40 41 if($attribute=='-') { 42 echo "答えは: " , $test1-$test2; 43 exit(); 44 } 45 46 if($attribute=='*') { 47 echo "答えは: " , $test1*$test2; 48 exit(); 49 } 50 51 if($attribute=='/') { 52 echo "答えは: " , $test1/$test2; 53 exit(); 54 } 55} 56?>
自分がやりたいのは、答えをecho()するのではなく答えをresultのところのinputフィールドに表示することなんですが、どうしたらいいでしょうか?
簡単なことかも知れないんですが、PHP初心者の自分にはわからなくて・・・
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。