Forum Moderators: coopster
I have a form that contains radio button groups. Each group is assigned a name and each radio button has a numerical value (1,2,3, etc). I want to total the values from each group and forward it to another page which displays that total.
How do I use PHP to take the value from each button group and add them? I can pass each individual answer to the second page ok, I'm just having difficulty totaling those values.
Thanks :)
<FORM METHOD="POST" ACTION="yourfile.php">
<input type="radio" name="value1" value="1">1<br>
<input type="radio" name="value1" value="2">2<br>
<input type="radio" name="value1" value="3">3<br>
<br>
<input type="radio" name="value2" value="1">1<br>
<input type="radio" name="value2" value="2">2<br>
<input type="radio" name="value2" value="3">3<br>
<input type="submit" value="Submit"></form>
in the php file that is to do your calculations you would do something similar to this
<?PHP
$value1 = $_POST['value1'];
$value2 = $_POST['value2'];// to get the total
$total = $value1 + $value2;echo $total;
?>
Hope it helps.
IamStang
Ok lets take this one step further.
instead of displaying the total number, how would one do something like:if $total <= "60" echo "F";
if $total <= "70" echo "D";etc.
LOL, you have it pretty close already. Just need a few extra items in there.
if($total <= 60){
echo "F"; }
elseif($total <= 70){
echo "D"; }
else { echo $total; }
I added the last part just to have a result to see if the first 2 aren't used. More for testing than anything.
You would also benefit from finding a script that does something similar to what you are trying to accomplish and having a look at their code. Plus, there are tons of tutorials on the web that are very informative.
Not saying you shouldn't ask for help here. Just saying that you should always try to take time to find the answer yourself. It's a great way to learn and you find other interesting ideas/thoughts/practices in your search.
Hope this helps,
IamStang
I appreciate your response and help. I have been searching the web and looking at other's code and learning from it. It seems easier to find examples of more difficult scripts than basic ones :)
I thought I almost had it last night, however I didn't. Thanks for your help and patience helping me learn. :)
I'll try that code and go from there.
Thanks again