dcsimg
www.webdeveloper.com
Results 1 to 5 of 5

Thread: Like button?

  1. #1
    Join Date
    Sep 2007
    Posts
    13

    Unhappy Like button?

    Hi,
    I want to implement like and dislike buttons in a webpage. I know how to do it if the voting sent the user to another page, but I want:
    1. The webpage to stay the same, no redirecting
    2. The MySQL database to update
    3. To disable the like and dislike buttons once the user has voted.
    I have no idea how to do this. Does anyone have the answer or a tutorial I could read?
    Thanks

  2. #2
    Join Date
    Jul 2012
    Location
    Vancouver
    Posts
    61
    If you know how to do the mysql/php part by itself - you just need to learn AJAX. Search on google ajax tutorials - or jquery ajax tutorials

  3. #3
    Join Date
    Mar 2012
    Posts
    1,831
    This can be done in php. You just set the action of the form to the same file. E.g. If the file is called index.php:

    <form action="index.php" method=get>
    <input type=submit name="vote" value="like">
    <input type=submit name="vote" value="dislike">
    </form>

    If you do not want to use a form, you can simulate it with anchors:

    <a href="index.php?vote=like">like</a>
    <a href="index.php?vote=dislike">dislike</a>

    In either case you need to allow for the url variable vote being NULL when index.php is first displayed.

  4. #4
    Join Date
    Jul 2012
    Location
    Vancouver
    Posts
    61
    Quote Originally Posted by jedaisoul View Post
    This can be done in php. You just set the action of the form to the same file. E.g. If the file is called index.php:

    <form action="index.php" method=get>
    <input type=submit name="vote" value="like">
    <input type=submit name="vote" value="dislike">
    </form>

    If you do not want to use a form, you can simulate it with anchors:

    <a href="index.php?vote=like">like</a>
    <a href="index.php?vote=dislike">dislike</a>

    In either case you need to allow for the url variable vote being NULL when index.php is first displayed.
    That's still redirecting, not leaving the webpage is making an ajax request... OP stated he/she knows how to do this already - but not how to do it without leaving the current page

  5. #5
    Join Date
    Sep 2007
    Posts
    13

    Smile Thanks!

    Thanks, Mistin! I will check on this AJAX thing
    Jedaisoul, Mistin is right, that needs redirecting, but thanks

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles