Page 1 of 1

Need urgent help in scripting

Posted: Tue Jul 21, 2009 3:59 am
by pawanphpdude
i have made a static page
below is the source code of the page.

Code: Select all

<html> 
<head> 
<title>Calculate</title> 
</head> 
<body> 
<form method="post" action="">
N1:<input type="text"><br />
N2:<input type="text"><br />
<input type="submit" name="Add" value="Add"> 
<input type="submit" name="Sub" value="Sub"> 
<input type="submit" name="Mul" value="Mul"> 
<input type="submit" name="Div" value="Div"> <br>
=:<input type="text"><br />
 
now what i want is that,
I want user to enter Numbers in N1 field and N2 field
and when user clicks on Add, sub, div, mul button.
then the interface calculates both N1 and N2
and display the result in = field.
thanks in advance
please help me

Re: Need urgent help in scripting

Posted: Tue Jul 21, 2009 11:44 am
by Christopher
You need to give names to the N1 and N2 <input> tags. This page will post to itself. You can access the values from the form in PHP using $_POST, such as:

Code: Select all

<?php
$result = 'error';
if (isset($_POST['Add'])) {
     $result = $_POST['N1'] + $_POST['N2'];
}
echo $result;
?>