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;
?>

Recommended Answers

All 3 Replies

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.

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

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;
}
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.