0

hi im still a beginner in PHP and this is the code i have so far and it only calculates value of two numbers put in manually. I want to generate two numbers and add the values.

<form name="form1" method="post" action="">
   value1: 
     <label>
  <input type="text" name="value1">
  </label>
  <p>&nbsp;</p>
  <p>
    <label>
    value2:  
    <input type="text" name="value2">
    </label>
  </p>

 
  <p>
    <label>
    <input type="submit" name="submit" value="calculate">
    </label>
	</form>


<?php
$_POST[calculate] =="add"; {
$result = $_POST[value1] + $_POST[value2];
}
echo $result;
?>

Edited by nav33n: Use [code][/code] tags to wrap your code for easy readability.

3
Contributors
3
Replies
6
Views
7 Years
Discussion Span
Last Post by manishmannan
0

hi im still a beginner in PHP and this is the code i have so far and it only calculates value of two numbers put in manually. I want to generate two numbers and add the values.

<form name="form1" method="post" action="">
   value1: 
     <label>
  <input type="text" name="value1">
  </label>
  <p>&nbsp;</p>
  <p>
    <label>
    value2:  
    <input type="text" name="value2">
    </label>
  </p>


  <p>
    <label>
    <input type="submit" name="submit" value="calculate">
    </label>
    </form>


<?php
$_POST[calculate] =="add"; {
$result = $_POST[value1] + $_POST[value2];
}
echo $result;
?>

end quote.

Hi,
Please try to explain clearly your issue.

Do you want to generate random numbers and add them into the texts boxes, then sum?
If yes, explain when you want to the numbers be generated? When page loads or when you click on the button?

regards.

Edited by mike_2000_17: Fixed formatting

0

my apologies, there is supposed to be a start button on which on clicking it would generate the numbers and them and calculate button sums them up

0

Please see this code

<?php
$randome = mt_rand();
$rand0me = mt_rand();
?>
<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
value1: 
<label>
<input type="text" name="value1" value="<?php echo $randome; ?>">
</label>
<p>&nbsp;</p>
<p>
<label>
value2: 
<input type="text" name="value2" value="<?php echo $rand0me; ?>">
</label>
</p>


<p>
<label>
<input type="submit" name="submit" value="calculate"><input type="hidden" name="form_submit" value="1">
</label>
</form>


<?php
if($_POST['form_submit'] == 1)
{
$_POST[calculate] =="add"; {
$result = $_POST[value1] + $_POST[value2];
}
echo $result;
}
?>

Edited by nav33n: Use [code][/code] tags to wrap your code for easy readability.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.