how do i have a Php sum with form?

Johnies

New member
I have this assignment. I'm supposed to make two text fields where i will write two numbers and add them in another page

<html>
<head>
<title>Test</title>
</head>
<body>
<form method="post" action="page2.php">
<input type="text" name="num1">
<br><input type="text" name="num2">
<input type="submit" value="OK">
</form>

what's the php script for page2?
 
<?php
if(isset($_POST)){

$number1 = $_POST['num1'];
$number2 = $_POST['num2'];

$total = $number1 + $number2;

echo "The total value is <strong>$total</strong>";

}
?>

++++++

Hope that helps. You should validate your form as well, make sure values are passed. you can make use of:
++++++
if(empty($_POST['num1'])){
# then do something
} else {
#do something else
}
 
Back
Top