html - How to get the value of a radio button in a table - PHP -
so had form contained 30 radio buttons, 3 in group same names selected 1 out of 3 1 used. want value of radio button set variable. working fine until decided stick in table. here have:
<form method="post"><table style="width: 99%"> <tr> <td style="width: 46px"> </td> <td>questions:</td> <td style="width: 85px">yes</td> <td style="width: 84px">no</td> <td style="width: 87px">don't know</td> </tr> <tr> <td style="width: 46px"> <span class="auto-style2"> <label id="q1"> q1.</label></span></td> <td>--------------------------------------------</td> <td style="width: 85px"> <input type="radio" name="question1" value="5" class="auto-style2"></td> <td style="width: 84px"> <input type="radio" name="question1" value="2" class="auto-style2"></td> <td style="width: 87px" class="auto-style30"> <input type="radio" name="question1" value="0" checked="true" class="auto-style2"></td> </tr> <tr> <td style="width: 46px" class="auto-style2"> <label id="q1">q2.</label></td> <td>--------------------------------------------</td> <td style="width: 85px"> <input type="radio" name="question2" value="5" class="auto-style2"></td> <td style="width: 84px"> <input type="radio" name="question2" value="2" class="auto-style2"></td> <td style="width: 87px" class="auto-style30"> <input type="radio" name="question2" value="0" checked="true" class="auto-style2"></td> </tr> <tr> <td style="width: 46px" class="auto-style2"> <label id="q1">q3.</label></td> <td>--------------------------------------------</td> <td style="width: 85px"> <input type="radio" name="question3" value="5" class="auto-style2"></td> <td style="width: 84px"> <input type="radio" name="question3" value="2" class="auto-style2"></td> <td style="width: 87px" class="auto-style30"> <input type="radio" name="question3" value="0" checked="true" class="auto-style2"></td> </tr> <tr> <td style="width: 46px" class="auto-style2"> <label id="q1">q4.</label></td> <td>--------------------------------------------</td> <td style="width: 85px"> <input type="radio" name="question4" value="5" class="auto-style2"></td> <td style="width: 84px"> <input type="radio" name="question4" value="2" class="auto-style2"></td> <td style="width: 87px" class="auto-style30"> <input type="radio" name="question4" value="0" checked="true" class="auto-style2"></td> </tr> <tr> <td style="width: 46px" class="auto-style2"> <label id="q1">q5. </label></td> <td>--------------------------------------------</td> <td style="width: 85px"> <input type="radio" name="question5" value="5" class="auto-style2"></td> <td style="width: 84px"> <input type="radio" name="question5" value="2" class="auto-style2"></td> <td style="width: 87px" class="auto-style30"> <input type="radio" name="question5" value="0" checked="true" class="auto-style2"></td> </tr> <tr> <td style="width: 46px" class="auto-style2"> <label id="q1">q6.</label></td> <td>--------------------------------------------</td> <td style="width: 85px"> <input type="radio" name="question6" value="5" class="auto-style2"></td> <td style="width: 84px"> <input type="radio" name="question6" value="2" class="auto-style2"></td> <td style="width: 87px" class="auto-style30"> <input type="radio" name="question6" value="0" checked="true" class="auto-style2"></td> </tr> <tr> <td style="width: 46px" class="auto-style2"> <label id="q1">q7.</label></td> <td>--------------------------------------------</td> <td style="width: 85px"> <input type="radio" name="question7" value="5" class="auto-style2"></td> <td style="width: 84px"> <input type="radio" name="question7" value="2" class="auto-style2"></td> <td style="width: 87px" class="auto-style30"> <input type="radio" name="question7" value="0" checked="true" class="auto-style2"></td> </tr> <tr> <td style="width: 46px" class="auto-style2"> <label id="q1">q8.</label></td> <td>--------------------------------------------</td> <td style="width: 85px"> <input type="radio" name="question8" value="5" class="auto-style2"></td> <td style="width: 84px"> <input type="radio" name="question8" value="2" class="auto-style2"></td> <td style="width: 87px" class="auto-style30"> <input type="radio" name="question8" value="0" checked="true" class="auto-style2"></td> </tr> <tr> <td style="width: 46px" class="auto-style2"> <label id="q1">q9.</label></td> <td>--------------------------------------------</td> <td style="width: 85px"> <input type="radio" name="question9" value="5" class="auto-style2"></td> <td style="width: 84px"> <input type="radio" name="question9" value="2" class="auto-style2"></td> <td style="width: 87px" class="auto-style30"> <input type="radio" name="question9" value="0" checked="true" class="auto-style2"></td> </tr> <tr> <td style="width: 46px" class="auto-style2"> <label id="q1" style="height: 21px">q10. </label></td> <td>--------------------------------------------</td> <td style="width: 85px"> <input type="radio" name="question10" value="5" class="auto-style2"></td> <td style="width: 84px"> <input type="radio" name="question10" value="2" class="auto-style2"></td> <td style="width: 87px" class="auto-style30"> <input type="radio" name="question10" value="0" checked="true" class="auto-style2"></td> </tr> </table> </form> <p>company name <span class="error">*</span></p> <input type="text" name="name" class="auto-style2"> <input type="submit" name="submit" value="submit" class="auto-style2"><span class="auto-style2"></span> <?php $score1 = $_post['question1']; $score2 = $_post['question2']; $score3 = $_post['question3']; $score4 = $_post['question4']; $score5 = $_post['question5']; $score6 = $_post['question6']; $score7 = $_post['question7']; $score8 = $_post['question8']; $score9 = $_post['question9']; $score10 = $_post['question10']; $weight1 = 1; $weight2 = 2; $weight3 = 3; $scoretotal1 = $score1*$weight3; $scoretotal2 = $score2*$weight2; $scoretotal3 = $score3*$weight2; $scoretotal4 = $score4*$weight1; $scoretotal5 = $score5*$weight1; $scoretotal6 = $score6*$weight3; $scoretotal7 = $score7*$weight2; $scoretotal8 = $score8*$weight2; $scoretotal9 = $score9*$weight1; $scoretotal10 = $score10*$weight1; $score = $scoretotal1 + $scoretotal2 + $scoretotal3 + $scoretotal4 + $scoretotal5 + $scoretotal6 + $scoretotal7 + $scoretotal8 + $scoretotal9 + $scoretotal10; ?>
i aware there several issues code, rookie. issue radio button values not being set variables. confirmed echoing variables.
any appreciated
thanks
edit:
easy fix; had move submit button form, when added table tags forgot submit button :)
code edited.
<form method="post"><table style="width: 99%"> <tr> <td style="width: 46px"> </td> <td>questions:</td> <td style="width: 85px">yes</td> <td style="width: 84px">no</td> <td style="width: 87px">don't know</td> </tr> <tr> <td style="width: 46px"> <span class="auto-style2"> <label id="q1"> q1.</label></span></td> <td>--------------------------------------------</td> <td style="width: 85px"> <input type="radio" name="question1" value="5" class="auto-style2"></td> <td style="width: 84px"> <input type="radio" name="question1" value="2" class="auto-style2"></td> <td style="width: 87px" class="auto-style30"> <input type="radio" name="question1" value="0" checked="true" class="auto-style2"></td> </tr> <tr> <td style="width: 46px" class="auto-style2"> <label id="q1">q2.</label></td> <td>--------------------------------------------</td> <td style="width: 85px"> <input type="radio" name="question2" value="5" class="auto-style2"></td> <td style="width: 84px"> <input type="radio" name="question2" value="2" class="auto-style2"></td> <td style="width: 87px" class="auto-style30"> <input type="radio" name="question2" value="0" checked="true" class="auto-style2"></td> </tr> <tr> <td style="width: 46px" class="auto-style2"> <label id="q1">q3.</label></td> <td>--------------------------------------------</td> <td style="width: 85px"> <input type="radio" name="question3" value="5" class="auto-style2"></td> <td style="width: 84px"> <input type="radio" name="question3" value="2" class="auto-style2"></td> <td style="width: 87px" class="auto-style30"> <input type="radio" name="question3" value="0" checked="true" class="auto-style2"></td> </tr> <tr> <td style="width: 46px" class="auto-style2"> <label id="q1">q4.</label></td> <td>--------------------------------------------</td> <td style="width: 85px"> <input type="radio" name="question4" value="5" class="auto-style2"></td> <td style="width: 84px"> <input type="radio" name="question4" value="2" class="auto-style2"></td> <td style="width: 87px" class="auto-style30"> <input type="radio" name="question4" value="0" checked="true" class="auto-style2"></td> </tr> <tr> <td style="width: 46px" class="auto-style2"> <label id="q1">q5. </label></td> <td>--------------------------------------------</td> <td style="width: 85px"> <input type="radio" name="question5" value="5" class="auto-style2"></td> <td style="width: 84px"> <input type="radio" name="question5" value="2" class="auto-style2"></td> <td style="width: 87px" class="auto-style30"> <input type="radio" name="question5" value="0" checked="true" class="auto-style2"></td> </tr> <tr> <td style="width: 46px" class="auto-style2"> <label id="q1">q6.</label></td> <td>--------------------------------------------</td> <td style="width: 85px"> <input type="radio" name="question6" value="5" class="auto-style2"></td> <td style="width: 84px"> <input type="radio" name="question6" value="2" class="auto-style2"></td> <td style="width: 87px" class="auto-style30"> <input type="radio" name="question6" value="0" checked="true" class="auto-style2"></td> </tr> <tr> <td style="width: 46px" class="auto-style2"> <label id="q1">q7.</label></td> <td>--------------------------------------------</td> <td style="width: 85px"> <input type="radio" name="question7" value="5" class="auto-style2"></td> <td style="width: 84px"> <input type="radio" name="question7" value="2" class="auto-style2"></td> <td style="width: 87px" class="auto-style30"> <input type="radio" name="question7" value="0" checked="true" class="auto-style2"></td> </tr> <tr> <td style="width: 46px" class="auto-style2"> <label id="q1">q8.</label></td> <td>--------------------------------------------</td> <td style="width: 85px"> <input type="radio" name="question8" value="5" class="auto-style2"></td> <td style="width: 84px"> <input type="radio" name="question8" value="2" class="auto-style2"></td> <td style="width: 87px" class="auto-style30"> <input type="radio" name="question8" value="0" checked="true" class="auto-style2"></td> </tr> <tr> <td style="width: 46px" class="auto-style2"> <label id="q1">q9.</label></td> <td>--------------------------------------------</td> <td style="width: 85px"> <input type="radio" name="question9" value="5" class="auto-style2"></td> <td style="width: 84px"> <input type="radio" name="question9" value="2" class="auto-style2"></td> <td style="width: 87px" class="auto-style30"> <input type="radio" name="question9" value="0" checked="true" class="auto-style2"></td> </tr> <tr> <td style="width: 46px" class="auto-style2"> <label id="q1" style="height: 21px">q10. </label></td> <td>--------------------------------------------</td> <td style="width: 85px"> <input type="radio" name="question10" value="5" class="auto-style2"></td> <td style="width: 84px"> <input type="radio" name="question10" value="2" class="auto-style2"></td> <td style="width: 87px" class="auto-style30"> <input type="radio" name="question10" value="0" checked="true" class="auto-style2"></td> </tr> <tr><input type="submit" name="submit"></input ></tr> </table> </form> <?php if(isset($_post['submit'])) { if(isset($_post['question1'])) { $score1 = $_post['question1']; echo "<br>".$score1."<br>"; } $score2 = $_post['question2']; $score3 = $_post['question3']; $score4 = $_post['question4']; $score5 = $_post['question5']; $score6 = $_post['question6']; $score7 = $_post['question7']; $score8 = $_post['question8']; $score9 = $_post['question9']; $score10 = $_post['question10']; $weight1 = 1; $weight2 = 2; $weight3 = 3; $scoretotal1 = $score1*$weight3; $scoretotal2 = $score2*$weight2; $scoretotal3 = $score3*$weight2; $scoretotal4 = $score4*$weight1; $scoretotal5 = $score5*$weight1; $scoretotal6 = $score6*$weight3; $scoretotal7 = $score7*$weight2; $scoretotal8 = $score8*$weight2; $scoretotal9 = $score9*$weight1; $scoretotal10 = $score10*$weight1; $score = $scoretotal1 + $scoretotal2 + $scoretotal3 + $scoretotal4 + $scoretotal5 + $scoretotal6 + $scoretotal7 + $scoretotal8 + $scoretotal9 + $scoretotal10; echo $score; } ?>
you have forgot add submit button form , didn't check submit button clicked. above works fine.
Comments
Post a Comment