我已經使用此代碼來計算v1,v2,v3的總和(總數),wihch是一個無線電輸入類型,所有數據庫中的所有數據都保存在TOTAL中。它存儲像144或444!所有3個輸入不是總和..請幫助我想把它作爲存儲的3個輸入如何在數據庫中存儲總和操作
...
<tr>
<th> Your attendance<font size="4" > </font></th>
<td> <input type="radio" name ="v1" value = "4" checked = "checked" onclick="updateTotal();"/></td>
<td> <input type="radio" name ="v1" value = "3" onclick="updateTotal();" /></td>
<td> <input type="radio" name ="v1" value = "2" onclick="updateTotal();" /></td>
<td> <input type="radio" name ="v1" value = "1" onclick="updateTotal();" /></td>
</tr>
<tr>
<th > Your grades <font size="4" > </font></th>
<td> <input type="radio" name ="v2" value = "4" onclick="updateTotal();" checked = "checked" /></td>
<td> <input type="radio" name ="v2" value = "3" onclick="updateTotal();" /></td>
<td> <input type="radio" name ="v2" value = "2" onclick="updateTotal();" /></td>
<td> <input type="radio" name ="v2" value = "1" onclick="updateTotal();" /></td>
</tr>
<tr>
<th >Your self-control <font size="4" > </font></th>
<td> <input type="radio" name ="v3" value = "4" onclick="updateTotal();" checked = "checked" /></td>
<td> <input type="radio" name ="v3" value = "3" onclick="updateTotal();" /></td>
<td> <input type="radio" name ="v3" value = "2" onclick="updateTotal();" /></td>
<td> <input type="radio" name ="v3" value = "1" onclick="updateTotal();" /></td>
</tr>
</tr>
</table>
<br>
<a href="evaE.php"> <td><input type="submit" name="submit" value="Submit">
<input type="reset" name="clear" value="clear" style="width: 70px"></td>
<input type="hidden" id="total" name="total" />
<script>
function updateTotal(){
var sumRad = 0;
var arrV1 = document.getElementsByName("v1");
var arrV2 = document.getElementsByName("v2");
var arrV3 = document.getElementsByName("v3");
for(var i=0; i<arrV1.length ; i++){
if(arrV1[i].checked == true){
sumRad += arrV1[i].value;
}
}
for(var i=0; i<arrV2.length ; i++){
if(arrV2[i].checked == true){
sumRad += arrV2[i].value;
}
}
for(var i=0; i<arrV3.length ; i++){
if(arrV3[i].checked == true){
sumRad += arrV3[i].value;
}
}
document.getElementById('total').value = sumRad ;
}
</script>
</form>
</center>
</div>
</body>
</html>
總和
的代碼的其餘部分是
<?php
session_start();
$Load=$_SESSION['login_user'];
include('../connect.php');
$sql= "Select name from student where ID='$Load'";
$username = mysql_query($sql);
$id=$_SESSION['login_user'];
if (isset($_POST['submit']))
{
$v1 = $_POST['v1'];
$v2 = $_POST['v2'];
$v3 = $_POST['v3'];
$total = $_POST['total'];
mysql_query("INSERT into Form1 (P1,P2,P3,TOTAL)
values('$v1','$v2','$v3','$total')") or die(mysql_error());
header("Location: mark.php");
}
?>
從你的[最後一個問題]的答案是什麼(http://stackoverflow.com/questions/13312033/php-store-calculate-the-total-mark-from-radio-input)?你爲什麼不在收到它們時將它們添加到PHP中? – mario