View Single Post
Old 02-21-2013, 05:29 PM   PM User | #1
sssunny
New Coder

 
Join Date: Jul 2012
Posts: 18
Thanks: 4
Thanked 0 Times in 0 Posts
sssunny is an unknown quantity at this point
php coding problem.!!..

i want to add two number,and then i want complier to ask me,if i want to add more number in previously added number,if i say yes it should add two more number to previous number and if i say no it should show the current result,for ex:if i want to add 5 and 8 it would be 13,then i want compiler to ask if i want to add more number,if no then it should show 13,if yes then it would add another two numbers in 13.

Here is the code i have tried
PHP Code:
<?php
if(isset($_POST['number1']) && isset($_POST['number2']))
{
$number1=$_POST['number1'];
$number2=$_POST['number2'];
$yes='';
$yes=$_POST['yes'];
function 
add($number1,$number2)
{
$number3$number1+$number2;
echo 
$number3;   
echo 
'do you want to add more numbers (y) or (n)';
}
if(
$yes=='y')
{
$sum1=$sum+add($number1,$number2);
echo 
'new total is'.$sum1;   
}
if(
$yes=='n')
{
echo 
$sum;   
}

add($number1,$number2);
}

?>
<form id="form1" name="form1" method="post" action="test.php">
<table width="100%" cellpadding="2">
  <tr>
    <td>number1:
      
        <label>
          <input type="text" name="number1" id="number1" />
        </label>
  </td>
  </tr>
  <tr>
    <td>number2:
      
        <label>
          <input type="text" name="number2" id="number2" />
        </label>
  </td>
  </tr>
  <tr>
    <td>
      <input type="submit" name="submit" id="submit" value="Submit" /></td>
  </tr>
  <tr>
    <td><label>
      <input type="text" name="yes" id="textfield" />
    </label></td>
  </tr>
</table>
</form>
sssunny is offline   Reply With Quote