Web Analytics Made Easy -
StatCounter Add to 'like' counter in MySql database - CodingForum

Announcement

Collapse
No announcement yet.

Add to 'like' counter in MySql database

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Add to 'like' counter in MySql database

    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
    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;?>')+'&amp;<?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>
    PHP
    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'");
    
    ?>
    I would greatly appreciate any help.

    Kind regards,
    Mark.
Working...
X
😀
🥰
🤢
😎
😡
👍
👎