I'm getting message NOT INSERTED all the time. it look all good when I PUT VALUES by my self in "values ('','','')" but to take it from the fields that I want it doesn't work. Can anybody help where I do it wrong?
So I would like to have in my database after clicking a button something like that:
Item Clicks
TV LG 55' 0.01
TV LG 55' 0.02
TV LG 55' 0.03
TV LG 55' 0.04
HTML FILE
<!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 FILE ( 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 script file: counting.js to make count of clicks.
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 file : extract.js for putting values if TVid and TvDiv in INPUT hidden.
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
}
check id in the table is a primary key. if it's primary key then you can't use 'First' constant for all row
values ('First','$id','$item')";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.