text1とtext2を足し算した結果をこのファイル自体に表示したいです。
表示される場所はどこでもいいです。
以下のコードではうまくいきません。ご教授頂ければ幸いです。
html
1<?php 2 3$text1 =''; 4$text2=''; 5 6if ($_SERVER['REQUEST_METHOD'] === 'POST'){ 7 $text1 = $POST['text1']; 8 $text2 = $POST['text2']; 9 $result = $text1 + $text2; 10 } 11 ?> 12 13<!DOCTYPE html> 14<html lang = "ja"> 15<head> 16 <meta charset = "utf-8"> 17 <title>calculator</title> 18 <link rel="stylesheet" href="styles.css"> 19</head> 20<body> 21<div id ="container"> 22 <h1>計算</h1> 23 <form action="" method="POST"> 24 <div id="container-1"> 25 <input type="text" id="text1" name="text1" placeholder="text1" value="<?php echo htmlspecialchars($text1, ENT_QUOTES, 'UTF-8'); ?>" onKeyup="this.value=this.value.replace(/[^0-9]+/,'')"> 26 <ul> 27 <li class="btn">+</li> 28 <li class="btn">−</li> 29 <li class="btn">×</li> 30 <li class="btn">÷</li> 31 </ul> 32 <input type="text" id="text2" name="text2" placeholder="text2" value="<?php echo htmlspecialchars($text2, ENT_QUOTES, 'UTF-8'); ?>" onKeyup="this.value=this.value.replace(/[^0-9]+/,'')"> 33 </div> 34 <input type="submit" id="result" value ="result"> 35 <?php echo htmlspecialchars($result, ENT_QUOTES, 'UTF-8'); ?>; 36</div> 37</form> 38</body> 39</html> 40
CSS
1body { 2 font-size: 16px; 3 font-family: Arial, sans-serif; 4} 5 6#container { 7 text-align: center; 8 width: 500px; 9 margin: 15px auto; 10} 11h1{ 12 font-size: 20px; 13 line-height:50px; 14 padding: 10px; 15} 16h1 ,ul > li { 17 border: 1px solid #ddd; 18 border-radius: 5px; 19} 20#container-1{ 21 display: flex; 22} 23ul{ 24 margin:auto; 25 list-style: none; 26 padding: 0; 27} 28li{ 29 width:20px; 30 margin: auto; 31 cursor: pointer; 32} 33#text1{ 34 height: 10px; 35 margin-top: 25px; 36} 37#text2{ 38 height: 10px; 39 margin-top: 25px; 40} 41#result{ 42 margin-top: 15px; 43 float:right; 44 cursor: pointer; 45 box-shadow: 0 4px 0 #0088cc; 46 width: 100px; 47} 48
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/03/03 05:08
2019/03/03 05:19
2019/03/03 05:26
2019/03/03 05:31
2019/03/03 05:50