troubleshooting Question

Echo does not works

Avatar of rrajani
rrajani asked on
PHP
6 Comments1 Solution204 ViewsLast Modified:
I am learning PHP and using examples from the book which is on version PHP_4.0.0 and on the server we have version PHP 5.2.6 installed.
Examples has 2 files:

Calculate_form.html
===============
<HTML>
<HEAD>
<TITLE>Calculation Form</TITLE>
</HEAD>
<BODY>

<FORM METHOD="post" ACTION="calculate.php">

<P>Value 1: <INPUT TYPE="text" NAME="val1" SIZE=10></p>

<P>Value 2: <INPUT TYPE="text" NAME="val2" SIZE=10></p>

<P>Calculation:<br>
<INPUT TYPE="radio" NAME="calc" VALUE="add"> add<br>
<INPUT TYPE="radio" NAME="calc" VALUE="subtract"> subtract<br>
<INPUT TYPE="radio" NAME="calc" VALUE="multiply"> multiply<br>
<INPUT TYPE="radio" NAME="calc" VALUE="divide"> divide</p>

<P><INPUT TYPE="submit" NAME="submit" VALUE="Calculate"></p>

</FORM>

</BODY>
</HTML>

calculate.php
===========
<?

if (($val1 == "") || ($val2 == "") || ($calc =="")) {
      header("calculate_form.html");
      exit;
}      

if ($calc == "add") {
      $result = $val1 + $val2;
} else if ($calc == "subtract") {
      $result = $val1 - $val2;
} else if ($calc == "multiply") {
      $result = $val1 * $val2;
} else if ($calc == "divide") {
      $result = $val1 / $val2;
}

?>

<HTML>
<HEAD>
<TITLE>Calculation Result</TITLE>
</HEAD>
<BODY>

<P>The result of the calculation is: <? echo "$result"; ?></p>

</BODY>
</HTML>

It is not echoing the result when click on Caclcuate button. It only displays the message The result of the calculation is:         and no result.....

Can anyone advice what is wrong........is it something to do with the version.......
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 6 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros