jquery - ajax and php updating mysql -
i having problem updating database.
basically trying everytime download link clicked download count in database goes up.
can point me in right direction have been trying right hours :(
here html.
<div class="button_border_dark"> <a id="linkcounter" href="http://www.derby-web-design-agency.co.uk/freeby-download/<?php echo $freebies_download ; ?>" target="_blank" title="download">click download file</a></div>
here jquery
<script> $('#linkcounter').bind('click',function(){ $.post("downloadcount.php",{ linkid: <?php echo $id ; ?>}); }); </script>
here downloadcount.php trying post data too, updates content.
<?php require_once("applications/constants/connection.php"); require_once("applications/controllers/basic.php"); if(isset($_request["linkid"])){ $linkid = sanitise($_post["linkid"]); $updatedownload = mysql_query("update freebies set download_count=`download_count` +1 id ='".$linkid."'") or die(mysql_error()); }
you don't problem!
is not incrementing? incrementing much? 1 process blocking other? problem people can cheat , make file has ben downloaded million times?
anyway, think code can simpler.
$('#linkcounter').click(function(){ $("#invisibleiframe").attr("src",$(this).attr("src"); $.post("downloadcount.php",{ linkid: <?php echo $id ; ?>}); return false; });
this need create invisible iframe, 1 downloaded file. after starting download, ajax request made. single event 2 things. made way stuff still works if js disabled.
Comments
Post a Comment