I want to update my database when i click the label in the infowindow. but i cant seems to update even when it shows that "You have donated" the value that i pass in is dynamic data which means that i have retrieve the value and pass it into the infowinow.
<script type="text/javascript">
function initialize() {
//sg map
var latlng = new google.maps.LatLng(1.3667, 103.8);
var myOptions = {
zoom: 11,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
<?php
$query = "SELECT * FROM standcharbranch";
$result = $mysqli->query($query);
while($branch = $result->fetch_array())
{
$amt = $branch['NumOfDonate'];
$totalAmt = $amt*0.05;
?>
//location marker
var marker = new google.maps.Marker({
position: new google.maps.LatLng(<?php echo $branch['latitude'];?>,<?php echo $branch['longtitude'];?>),
map: map,
title: "<?php echo $branch['Location'];?>",
icon: "./Images/sclogo.png"
});
var infowindow = new google.maps.InfoWindow();
//Add an onclick event to the marker that will load the overlay.
google.maps.event.addListener(marker, 'click', function() {
[B]Here is the label to click for the update[/B]
var contentString = "<?php echo $branch['Location'].'<br/><br/>'.'$'.$totalAmt.'<br/><br/>'.'<label id=donateCharity onclick=charityDonate()>Donate</label>'?>";
infowindow.setContent(contentString);
infowindow.open(map,this);
});
<?php
}
?>
}
function charityDonate(){
<?php
[B]Here is the problem[/B]
// construct your SQL statement
$sql = "UPDATE standcharbranch SET NumOfDonate=".($branch['NumOfDonate']+1)." WHERE Location='".$branch['Location']."'";
$checkresult=$mysqli->query($sql);
if($branch['Location']!=""){?>
alert("You have donated");
<?php
}
else if(!$checkresult){
?>
alert("Failed to donated");
<?php
}
$mysqli->close();
?>
}
</script>