无法在数据库MYSQLI中插入值我做错了什么?

时间:2017-09-16 18:49:11

标签: javascript php jquery html

我一直收到消息NOT INSERTED。当我在“值('','','')”中使用我自己的值时,它看起来很好,但是从我想要的字段中取出它不起作用。任何人都可以帮助我做错了吗?

所以我想点击一个类似的按钮后进入我的数据库:

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 如果隐藏了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
 }

1 个答案:

答案 0 :(得分:0)

检查表中的id是主键。 如果它是主键那么你就不能对所有行使用'First'常量 值('First','$ id','$ item')“;