knoahg Posted March 18, 2010 Share Posted March 18, 2010 Hi people im still a begginer in PHP this is the code i have so far and it only accepts entering values and adding with the button. So how can i generate two random numbers on the two boxes and calculate the result. Thank You. <form name="form1" method="post" action=""> value1: <label> <input type="text" name="value1"> </label> <p> </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; ?> [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/195648-generating-two-random-numbers-in-a-texarea-and-adding-their-values/ Share on other sites More sharing options...
The Little Guy Posted March 19, 2010 Share Posted March 19, 2010 You can do it like this: <form name="form1" method="post" action=""> value1: <label> <input type="text" name="value1" value="<?php echo rand(0, 1000000); ?>"> </label> <p> </p> <p> <label> value2: <input type="text" name="value2" value="<?php echo rand(0, 1000000); ?>"> </label> </p> <p> <label> <input type="submit" name="submit" value="calculate"> </label> </form> <?php if($_POST[calculate] == "add"){ $result = $_POST['value1'] + $_POST['value2']; } echo $result; ?> Link to comment https://forums.phpfreaks.com/topic/195648-generating-two-random-numbers-in-a-texarea-and-adding-their-values/#findComment-1028428 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.