PHP Operator help

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
srvishnukumar
Forum Newbie
Posts: 1
Joined: Sun Nov 07, 2010 8:00 am

PHP Operator help

Post by srvishnukumar »

Hi Friends,

Am New for PHP code. here am doing an small & basic code about operators. but i cant get result idont know that what is going wrong on my code. plz frnds guide me for this following code :-

Code: Select all

<?php
$x=$_POST['x'];
$y=$_POST['y'];
$result=$_POST['submit'];
if($result=='ADD')
{
$result=$x+$y;
echo $result;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>PHP Operators</title>
</head>

<body>

<div>
  <p align="justify">First Value   
    <input type="text" name="x" id="" />
  </p>
  <p align="justify">
    Second Value
    <input type="text" name="y" id="" />
  </p>
  <p align="justify">Result 
    <input type="text" name="result" />
  </p>
  <form id="form1" name="form1" method="post" action="" >
    
    <div align="justify">
      <input name="submit" type="submit" id="" value="ADD" />
      <input name="submit" type="submit" id="" value="SUB" />
      <input name="submit" type="submit" id="" value="MUL" />
      <input name="submit" type="submit" id="" value="DIV" />
      <input name="submit" type="submit" id="" value="CLR" />
    </div>
  </form>
  <p align="justify">&nbsp;</p>
</div>


</body>
</html>
Thanks with
Vishnukumar SR
Last edited by Benjamin on Sun Nov 07, 2010 11:34 am, edited 1 time in total.
Reason: Added [syntax=php] tags.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: PHP Operator help

Post by requinix »

If you want the result in the textbox then you have to put it there yourself. You have an echo $result; that will work but you put it in the wrong place.
s992
Forum Contributor
Posts: 124
Joined: Wed Oct 27, 2010 3:06 pm

Re: PHP Operator help

Post by s992 »

Your <form> needs to start before the input fields for them to be included:
[syntax]
<form id="form1" name="form1" method="post" action="" >
<p align="justify">First Value
<input type="text" name="x" id="" />
</p>
<p align="justify">
Second Value
<input type="text" name="y" id="" />
</p>
<p align="justify">Result
<input type="text" name="result" />
</p>


<div align="justify">
<input name="submit" type="submit" id="" value="ADD" />
<input name="submit" type="submit" id="" value="SUB" />
<input name="submit" type="submit" id="" value="MUL" />
<input name="submit" type="submit" id="" value="DIV" />
<input name="submit" type="submit" id="" value="CLR" />
</div>
</form>
[/syntax]
Post Reply