<img id="image" src="jj.png" onclick="randomizeImage();"/>
<h2 id="Score" name="Score1">0</h2>
<script>
var counter=0;
function randomizeImage() {
counter++;
var test= document.getElementById('Score');
test.innerHTML= counter;
}
</script>
<?php
$con = mysql_connect("localhost","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("database", $con);
$user_Name = $_COOKIE["username"]; //i stored the username as a cookie and retrieved it here
echo $user_Name; //echo it so i can check if it is right
$New= $_POST["Score"]; //**this is the part which is undefined**
$sql = "UPDATE User SET Score = '$New' WHERE ID='$user_Name'";
if (!mysql_query($sql,$con))
{
die('Error please try again ' . mysql_error());
}
mysql_close($con)
?>
I have an image that whenever i click on it, it will call a function which will increase a counter by 1. This score will be reflected on the html side and increase whenever i click on the image. However now i want to bring this counter data into php where i can upload it onto a database where it matches the user's username which he/she entered in a previous phpfile. I cant bring the value of score over? It keeps saying undefined index.
I have two colums called ID and Score. ID is where i score the user's username and Score is the score from the counter. I want the Score to updated everytime the image is pressed with respect to the username.
Database name is :database Table name is: User
Is there anyway to do this without AJAX?