簡體   English   中英

無法在數據庫MYSQLI中插入值我做錯了什么?

[英]Can't insert values in database MYSQLI what I'm doing wrong?

我一直收到未插入的消息。 當我自己在“ values('','','')中輸入值時,一切看起來很好但是從我想要的字段中獲取它卻不起作用。 有人可以在我做錯事情的地方提供幫助嗎?

所以我想在我的數據庫中單擊類似的按鈕之后:

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腳本文件:count.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,用於在隱藏INPUT中的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
 }

表中的檢查ID是主鍵。 如果它是主鍵,則不能對所有行使用“ First”常量
值(“第一”,“ $ id”,“ $ item”)”;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM