Page 1 of 1

PHP Operator help

Posted: Sun Nov 07, 2010 8:08 am
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

Re: PHP Operator help

Posted: Sun Nov 07, 2010 11:26 am
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.

Re: PHP Operator help

Posted: Sun Nov 07, 2010 11:36 am
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]