Hi guys. I have no experience with AJAX at all; however, I understand that I need to use this as I want to be able to let a user click on a 'thumbs up' button to add to a like counter without reloading the page.
I would really appreciate some help on this issue. I am developing a business directory and everything so far works how it should apart from this issue. I have done some reading up and have coded the following:
HTML
PHP
I would greatly appreciate any help.
Kind regards,
Mark.
I would really appreciate some help on this issue. I am developing a business directory and everything so far works how it should apart from this issue. I have done some reading up and have coded the following:
HTML
Code:
<script type="text/javascript" src="prototype.js"></script> <script> function sendRequest() { new Ajax.Request("test.php", { method: 'post', postBody: '<?php $Company;?>'+$F('<?php $Company;?>')+'&<?php $Code;?>='+$F('<?php $Code;?>') onComplete: showResponse }); } function showResponse(req){ $('pr_likes').innerHTML= req.responseText; } </script> <body> <div class="pr_thumb"> <?php $Code = $sr[$ii]['postcode']; $Company = $sr[$ii]['company_name']; ?> <form id="test" onsubmit="return false;"> <input type="hidden" name="<?php $Company;?>" id="<?php $Company;?>" > <input type="hidden" name="<?php $Code;?>" id="<?php $Code;?>" > <input type="submit" value="submit" onClick="sendRequest()"> </form> </div> </body>
Code:
<?php $companyName=($_REQUEST['$Company']); $postCode=($_REQUEST['$Code']); // connect to the database mysql_connect("*****", "*****") or die(mysql_error()); mysql_select_db("******") or die(mysql_error()); mysql_query("UPDATE businesses SET number_likes = number_likes+1 WHERE company_name = '$companyName' AND postcode = '$postCode'"); ?>
Kind regards,
Mark.