我已经使用此代码来计算 v1、v2、v3 的总和(总和),它是一个无线电输入类型,所有存储在数据库中的东西都可以预期为 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");
}
?>