0
我有一個代碼在這裏插入所有的數據到數據庫......我的問題它不工作什麼是我的代碼的問題?任何人都可以看看我的代碼,看看有什麼不對嗎?請我的php代碼不會插入
的html代碼:
<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代碼:
<?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");
}
?>
得分腳本:
<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>
我不能找到什麼錯我的代碼...我的插入查詢不工作,如果我點擊按鈕,它不能保存。
想向我們展示了錯誤消息('mysql_error()')?此外,[不使用'mysql_ *'](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php?rq=1); 'mysql_ *'函數已過時,[已棄用](http://us3.php.net/manual/en/intro.mysql.php),並且不安全。使用['MySQLi'](http://us3.php.net/manual/en/book.mysqli.php)或['PDO'](http://us3.php.net/manual/en/intro。相反,pdo.php)。最重要的是,你可以開放SQL注入。 –
你好,我的名字是'; DROP TABLE得分; (」 – bjb568