I currently have a database table with 2 columns: Photo No. & Vote Count. I would like to increase the vote count number in the database when the respective photo is pressed on the html page. Also, I did not want to go to another page as there's a overlay content when the photo is pressed. (thus there's no action in the form tags.
HTML
<form action="" method="post">
<input id="box1" type="submit">
<input id="result1" name="result1" type="text" value="0"/>
</form>
PHP
<?php
$link = mysqli_connect("localhost", "root", "", "votingcount");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
$sql = "UPDATE vote_result SET vote_count = vote_count + 1 WHERE photo_no=1";
if(mysqli_query($link, $sql)){
echo "Records added successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// close connection
mysqli_close($link);
?>
to run php
$(function() {
$('form').bind('submit', function(){
$.ajax({
type: 'post',
url: "insert.php",
data: $("form").serialize(),
success: function() {
}
});
return false;
});
});
What I've done was to only allow the first photo vount count to be updated in the database. But I have 7 other photos which I would also like to update the respective vote count when the respective photos are clicked.