0
我得到的消息一直沒有被插入。當我在「values('','','')」中輸入VALUE時,它看起來都很好,但是從我希望它不起作用的字段中取值。任何人都可以幫助我做錯了嗎?無法在數據庫MYSQLI中插入值我做錯了什麼?
所以我想在我的數據庫點擊一個按鈕類似的東西后:
Item Clicks
TV LG 55' 0.01
TV LG 55' 0.02
TV LG 55' 0.03
TV LG 55' 0.04
HTML文件
<!DOCTYPE html>
<html>
<head> </head>
<body>
<form name="form" method="post" action="clicking.php">
<span id="TVid">TV LG 55' </span>
<input type="hidden" name="TVid1" id="TVid1" >
<hr class="soft"/>
<div class="control-group">
<label><span id="TvDiv"> 0.00</span></label>
<input type="hidden" name="TvDiv1" id="TvDiv1" >
</div>
<input type="submit" name="b1" value="Quick Click" id="TvButton" onclick="aa(), bb()">
</div><br>
</form>
<script src="counting.js"> </script>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
</script>
<script src="extract.js"> </script>
</body>
</html>
PHP文件(clicking.php
):
<?php
$con = mysqli_connect("localhost", "root", "") or die("not connected");
$mydb = mysqli_select_db($con, "quickclicks") or die("no db found");
if($con){
echo "connection good";
} else{
echo "error in cnnection";
}
if($mydb){
echo "connection good";
} else{
echo "error in cnnection";
}
$item = $_POST ['TVid1'];
$clicks = $_POST ['TvDiv1'];
$sql = "insert into clicks (id,item,clicks)
values ('First','$item','$clicks')";
if(!mysqli_query($con, $sql)) {
echo 'not inserted';
}else {
echo 'Insterted';
}
header("refresh:10; url=new.html");
?>
Java腳本文件:counting.js 來計算點擊次數。
var LGtv = 0.00;
function aa(){
if (LGtv < 0.05){
document.getElementById('TvDiv').innerHTML = LGtv +=0.01;
} else {
document.getElementById('TvDiv').innerHTML = "You are a WINNER!";
}
}
jQuery的文件:extract.js 爲把值如果TVID和TvDiv輸入隱藏。
function bb(){
var s1 = document.getElementById('TVid').innerHTML;
document.form.TVid1.value = s1;
alert ("The value of the hidden field is " + document.form.TVid1.value);
// for testing
var s2 = document.getElementById('TvDiv').innerHTML;
document.form.TvDiv1.value = s2;
alert ("The value of the hidden field is " + document.form.TvDiv1.value);
// for testing
}
瞭解準備好的發言防止SQL注入 – Jens
使用mysqli_error給GEZ錯誤信息 – Jens
「not inserted」並不是一個特別有用的錯誤信息。用mysqli_error($ con)檢查* actual *錯誤信息提示:你的代碼對SQL注入是開放的,所以你的SQL語法 – David