2014-03-26 70 views
0

嘿,我很好,我想出瞭如何設計一個PHP回聲,這是很常識,但有一個醜陋的彩色框只是等待答案,有沒有一種方法來顯示框時,用戶點擊計算他們想?我的網站 - http://codepen.io/willc86/pen/BrEmt雖然PHP不會工作,只是爲了造型的目的,但我相信你會理解這個概念。我需要JavaScript嗎?在PHP中?

這是我的PHP/HTML

<html> 
    <body> 

     <style><?php include "style.css" ?></style> 



     <form action="index.php" method="POST"> 

     <table border="1"> 

     <td> 
     <p>insert value one: <input type="text" name="num1"> <br> 
     <p>insert value two: <input type="text" name="num2"> <br> 
     </td> 

     <td> 
      <input type="submit" name="add" value="Addition"> 
      <input type="submit" name="sub" value="Subtraction"> 
      <input type="submit" name="mult" value="Multiplication"> 
      <input type="submit" name="div" value="Division"> 
      <input type="submit" name="all" value="Display All"> 
     </td> 
     </table> 
     </form> 



<div id="answer"> 

    hello 
<?php 

if (isset($_POST['num1']) && ($_POST['num2'])){ 
    $val1 = $_POST['num1']; 
    $val2 = $_POST['num2']; 
    $add = $val1+$val2; 
    $sub = $val1-$val2; 
    $mult = $val1*$val2; 
    $div = $val1/$val2; 
} 

if (isset($_POST['add'])){ 
    echo $add; 
} 



?> 
     </div>  


    </body> 
</html> 

,這是我的CSS

body{ 
    background-color:#f0f0f0; 
} 

table{ 
    margin:50px auto; 
    background-color: tan; 
    border: 2px solid black; 
} 

#answer{ 
margin:auto; 
    width:100px; 
    height: 100px; 
    background-color: tan; 
text-align:center; 
border: solid black 1px; 
line-height: 100px; 
} 
+0

把' 'if'語句中的div'? – jeroen

回答

0

把你的標籤中你的PHP的if條件,就像這樣:

<?php 

if (isset($_POST['num1']) && ($_POST['num2'])){ 

    echo("<div id=\"answer\">"); 
    $val1 = $_POST['num1']; 
    $val2 = $_POST['num2']; 
    $add = $val1+$val2; 
    $sub = $val1-$val2; 
    $mult = $val1*$val2; 
    $div = $val1/$val2; 

if (isset($_POST['add'])){ 
    echo $add; 
} 

echo("</div>"); 

} 

?>