I have a code here that inserts all the data to the database...my problem its not working what is the problem with my code? can anyone look for my code and see what wrong? Please
html code:
<form method="post" name="frm" id="frm" >
<input type="text" name="name1" id="query1" onBlur="getvalues1()" />
<input type="radio" name="optA" value="1" onClick="optTotal()" />1
<input type="radio" name="optA" value="2" onClick="optTotal()" />2
<input type="radio" name="optA" value="3" onClick="optTotal()" />3
|
<input type="radio" name="optB" value="1" onClick="optTotal()" />1
<input type="radio" name="optB" value="2" onClick="optTotal()" />2
<input type="radio" name="optB" value="3" onClick="optTotal()" />3
|
<input type="radio" name="optC" value="1" onClick="optTotal()" />1
<input type="radio" name="optC" value="2" onClick="optTotal()" />2
<input type="radio" name="optC" value="3" onClick="optTotal()" />3
|
<input type="radio" name="optD" value="1" onClick="optTotal()" />1
<input type="radio" name="optD" value="2" onClick="optTotal()" />2
<input type="radio" name="optD" value="3" onClick="optTotal()" />3
<input type="text" name="total" id="total" onKeyUp="optTotal()" /><br />
<input type="text" name="aic1" id="aic1"/>
<input type="text" name="batchcode1" id="batchcode1" /><br>
<input type="submit" value="Test" name="calculate" id="press" />
<br />
</form>
php code:
<?php
if(isset($_POST['calculate']))
{
$name = array_key_exists('name1', $_POST) ? $_POST['name1'] : null;
//$name = $_POST['name'];
$score1 = array_key_exists('optA', $_POST) ? $_POST['optA'] : null;
//$score1 = $_POST['optA'];
$score2 = array_key_exists('optB', $_POST) ? $_POST['optB'] : null;
//$score2 = $_POST['optB'];
$score3 = array_key_exists('optC', $_POST) ? $_POST['optC'] : null;
//$score3 = $_POST['optC'];
$score4 = array_key_exists('optD', $_POST) ? $_POST['optD'] : null;
//$score4 = $_POST['optD'];
$aic = $_POST['aic1'];
//$score3 = $_POST['optC'];
$batchcode = $_POST['batchcode1'];
//$score4 = $_POST['optD'];
$total = ($score1 + $score2 + $score3 + $score4);
mysql_query("INSERT INTO score (name,score1,score2,score3,score4,total,aic,bathcode) VALUES ('$name','$score1','$score2','$score3','$score4','$total','$aic','$batchcode')");
header("Location:home.php");
}
?>
score script:
<script>
function optTotal()
{
var a1 = document.querySelector('input[name="optA"]:checked');
var b1 = document.querySelector('input[name="optB"]:checked');
var c1 = document.querySelector('input[name="optC"]:checked');
var d1 = document.querySelector('input[name="optD"]:checked');
if (a1 != null)
a1 = parseFloat(a1.value);
else
a1 = 0;
if (b1 != null)
b1 = parseFloat(b1.value);
else
b1 = 0;
if (c1 != null)
c1 = parseFloat(c1.value);
else
c1 = 0;
if (d1 != null)
d1 = parseFloat(d1.value);
else
d1 = 0;
document.frm.total.value=parseFloat(a1)+parseFloat(b1)+parseFloat(c1)+parseFloat(d1);
}
</script>
i cant find whats wrong with my code...my insert query is not working its not saving if i click the button.