PHP calculator solution

Source: Internet
Author: User
The PHP calculator php makes a calculator. Why does the page refresh as long as it is computed? but the value of the first text box remains unchanged, and the value of the second text box is gone, is this the default situation .. Below is my code? Why ?? & Lt ;! DOCTYPE & nbsp; html & nbsp; PUBLIC & nbsp; PHP calculator
Why does a calculator made by php only require a little calculation? the page is refreshed, but the value of the first text box remains unchanged, and the value of the second text box is gone. Is this the default case .. Below is my code? Why ??








$ Mess = "";

If (isset ($ _ POST ["sub"]) {

If ($ _ POST ["num1"] = ""){
$ Mess. = "The first number cannot be blank!
";
} Else {
If (! Is_numeric ($ _ POST ["num1"]) {
$ Mess. = "The first number must be a number!
";
}

}
If (is_numeric ($ _ POST ["num1"]) {
If ($ _ POST ["num2"] = ""){
$ Mess. = "The second number cannot be blank!
";
} Else {
If (! Is_numeric ($ _ POST ["num2"]) {
$ Mess. = "The second number must be a number!
";
} Else {
If ($ _ POST ["opt"] = "/" & $ _ POST ["num2"] = 0 ){
$ Mess. = "The divisor cannot be 0 ";
}

}
}
}


}

?>




Calculator


If (isset ($ _ POST ["sub"]) {
Echo' ';
If (! $ Mess ){
$ Sum = 0;
Switch ($ _ POST ["opt"]) {
Case "+ ";
$ Sum = $ _ POST ["num1"] + $ _ POST ["num2"]; break;
Case "-";
$ Sum = $ _ POST ["num1"]-$ _ POST ["num2"]; break;
Case "*";
$ Sum = $ _ POST ["num1"] * $ _ POST ["num2"]; break;
Case "/";
$ Sum = $ _ POST ["num1"]/$ _ POST ["num2"]; break;
Case "% ";
$ Sum = $ _ POST ["num1"] % $ _ POST ["num2"]; break;
}

Echo "result: {$ _ POST ['num1']} {$ _ POST ['opt']} {$ _ POST ['num2'] }={ $ sum }";

} Else {
Echo $ mess;
}

Echo'';
}


?>









?

No score. thank you !!!! Input

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.