0

Really simple question but can't seem to get anything to work with it?

I have a standard HTML link:

<a href=""> <i class="icon icon-arrow-circle-o-up"></i> Like </a>

I would like to use it as a submit button like a form so once someone clicks it I could run the following code:

if(isset($_POST['like'])){
mysql_query"UPDATE comments WHERE comment_id='$comment_id' SET like='1'";
}

Would this be an "On click" event or something or would I have to use javascript?

3 Answers3

0

You're looking for Ajax:

<a href="" id="like"><i class="icon icon-arrow-circle-o-up"></i> Like </a>

Javascript (jQuery):

$('#like').onClick(function() {
    $.ajax({
        method: 'post',
        url: 'url/to/php/script.php',
        data: {commentId: commentId}, // Set commentId to the actual commentId
    });
});
Terry Harvey
  • 9,286
  • 1
  • 17
  • 22
0

Add some ID to your form, for instance: "myForm".

Then you change your HTML link code like so:

<a href="" onClick="javascript:document.getElementById('myForm').submit();"> <i class="icon icon-arrow-circle-o-up"></i> Like </a>
Đuro Mandinić
  • 693
  • 1
  • 8
  • 26
-1

Use the HTML-Form:

<form action="yourfile.php" method="POST">
   <input type="submit" value="like" />
</form>

Put the PHP-Code into a external file (in this case yourfile.php)