Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-05-2011, 05:02 PM   PM User | #1
nortski
New to the CF scene

 
Join Date: Sep 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
nortski is an unknown quantity at this point
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.
nortski is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:50 PM.


Advertisement
Log in to turn off these ads.