Need urgent help in scripting

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pawanphpdude
Forum Newbie
Posts: 1
Joined: Tue Jul 21, 2009 3:55 am

Need urgent help in scripting

Post 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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Need urgent help in scripting

Post 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;
?>
(#10850)
Post Reply