Dash McElroy wrote:
You are referencing the variables properly on the first if line, but then
you're calling $var1 and $var2 w/o using $_GET. Add that or do this:

$var1 = $_GET['var1'];
$var2 = $_GET['var2'];

You may also want to use !isset($varname) instead of checking to see if
the variables are equal to a space char (" ").
isset() should not be preferred for variables coming from $_POST, $_GET or $_REQUEST

cause empty form-fields ARE set, so isset() will return TRUE

use empty() instead!

-Dash

"I have made mistakes but I have never made the mistake of claiming
that I have never made one."
		-- James Gordon Bennett

On Wed, 29 Jan 2003, Wade wrote:


01292003 1540 CST

When I run this script I get the html at the end but no $result. If the
result is run on the same page as the output, there shouldnt be anything
variable wise stopping this from running, right?

Wade

<?php
    if (($_POST["val1"] == " ") || ($_POST["val2"] == " ") ||
($_POST["calc"] == " "))
    {
        header("Location: http://localhost/Learning PHP/PHP Fast &
Easy/Ch_6/calculate_form.html");
        exit;
    }

    if ($_POST["calc"] == "add")
    {
        $result = $val1 + $val2;
    }

        else if ($_POST["calc"] == "subtract")
        {
             $result = $val1 - $val2;
        }

        else if ($_POST["calc"] == "multiply")
        {
             $result = $val1 *  $val2;
        }

        else if ($_POST["calc"] == "divide")
        {
            $result = $val1 / $val2;
        }
you should use switch()

switch ($_POST["calc"]) {
	case "add": $result = $_POST["val1"] + $_POST["val2"]; break;
	....
	default: $result = 'SOME ERROR';
}
?>

<html>
<head>
<title>Calculation Result</title>
<head>

<body>
    <p>The result of the calculation is: <?php "$result"; ?></p>
</body>
</html>


--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--
Sebastian Mendel

[EMAIL PROTECTED]

www.sebastianmendel.de
www.tekkno4u.de
www.nofetish.com


--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to