Can't print output with single calculation calculator

时间:2017-03-22 18:45:45

标签: php html

I'm trying to create a calculator that just multiplies two numbers together and outputs the result on the same page. Can someone please look at my code and tell me what I'm missing because I haven't been able to find it.

<html>
<head>
<title>Calculator</title>
<link type="css/text", rel="stylesheet", href="calculatorsh.css"/>
</head>
<body>

<div>
    <p>This is a calculator that multiplies two numbers together.</p>
    <form method="post" action="">
    <p><label>First Number:<input type="text" name="number1" /></label></p>
    <p><label>Second Number:<input type="text" name="number2"/></label></p>
    <input type="submit" value='Calculate'/>

    </form>
</div>
<br>
<div>
    Result:

    <?php
    if(isset($_POST['number1'])) && (isset($_POST['number2'])){
    $number1=$_POST['number1'];
    $number2=$_POST['number2'];
    $a=$number1*$number2;
    echo $a;
    }
    ?>

</div>  

</body

</html>

1 个答案:

答案 0 :(得分:2)

Get rid of the extra parentheses in your if statement.

if(isset($_POST['number1']) && isset($_POST['number2'])){
    $number1 = $_POST['number1'];
    $number2 = $_POST['number2'];
    $a = $number1*$number2;
    echo $a;
}