PHP - Store & Calculate the total mark from radio input
Posted
by
user1806136
on Stack Overflow
See other posts from Stack Overflow
or by user1806136
Published on 2012-11-09T16:29:17Z
Indexed on
2012/11/09
17:00 UTC
Read the original article
Hit count: 315
I have designed a small web-based system that have a school evaluation form to ask specific users who can access the system" some questions and the input will be a radio type ( 1 or 2 or 3 or 4)! the code is working and can inserts the input into the database but i don't know the correct query to calculate the total mark and store it in the database, this is currently working code below:
<?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");
}
?>
<html>
<head>
<?php
if(!isset($_SESSION['login_user']))
header("Location:index.html");
?>
<title>Q&A Form</title>
</head>
<body>
<center><form method="post" action="" >
<table style="width: 20%" >
<tr>
<th> Criteria </th>
<th> </th>
</tr>
<tr>
<th> Excellent </th>
<td > 4 </td>
</tr>
<tr>
<th > Good <font size="3" > </font></th>
<td> 3 <font size="4" > </font></td>
</tr>
<tr>
<th > Average <font size="3" > </font></th>
<td > 2 <font size="4" > </font></td>
</tr>
<tr>
<th > Poor <font size="3" > </font></th>
<td > 1 <font size="4" > </td>
</tr>
<font size='4'>
<table style="width: 70%">
<tr>
<th > School Evaluation <font size="4" > </font></th>
<tr>
<th > Criteria <font size="4" > </font></th>
<th> 4<font size="4" > </font></th>
<th> 3<font size="4" > </font></th>
<th> 2<font size="4" > </font></th>
<th> 1<font size="4" > </font></th>
</tr>
<tr>
<th> Your attendance<font size="4" > </font></th>
<td> <input type="radio" name ="v1" value = "4" checked = "checked" /></td>
<td> <input type="radio" name ="v1" value = "3" /></td>
<td> <input type="radio" name ="v1" value = "2" /></td>
<td> <input type="radio" name ="v1" value = "1" /></td>
</tr>
<tr>
<th > Your grades <font size="4" > </font></th>
<td> <input type="radio" name ="v2" value = "4" checked = "checked" /></td>
<td> <input type="radio" name ="v2" value = "3" /></td>
<td> <input type="radio" name ="v2" value = "2" /></td>
<td> <input type="radio" name ="v2" value = "1" /></td>
</tr>
<tr>
<th >Your self-control <font size="4" > </font></th>
<td> <input type="radio" name ="v3" value = "4" checked = "checked" /></td>
<td> <input type="radio" name ="v3" value = "3" /></td>
<td> <input type="radio" name ="v3" value = "2" /></td>
<td> <input type="radio" name ="v3" value = "1" /></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>
<?php
$total = $v1+ $v2 + $v3;
?>
</form>
</center>
</div>
</body>
</html>
i used this query but it doesn't work out .. any help please?
<?php
$total = $v1+ $v2 + $v3;
?>
© Stack Overflow or respective owner