PHP and OnClick Event

Discussion in 'PHP' started by inklight, Nov 3, 2010.

  1. #1
    Hi
    I'm trying to got input from JS event OnClick () that we'll count how many time th visitor press on link and store it in MySQL DB the JS Code will be something like this
    <a href="http://www.mysite.com/index.php?p=324" OnClick="Count The Clicks" > My Link </a>
    HTML:
    So the clicks can stored on PHP variable or on Function so I can call it any time on the site.
    as i read that can do it using HTML Post attribute so can assist values of click times ..Or using AJAX because it have ability to communicate with the server
     
    inklight, Nov 3, 2010 IP
  2. HowDoYou

    HowDoYou Well-Known Member

    Messages:
    443
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    130
    #2
    JUST php:
    on submit form, call a php script to count the click, and save it to the database.
    then redirect to your link location.
     
    HowDoYou, Nov 3, 2010 IP
  3. mdrobiul

    mdrobiul Peon

    Messages:
    186
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You need to move ajax solution. I'm not sure, but to give you a fast hint is:

    <a href="http://www.mysite.com/index.php?p=324" OnClick="count()" > My Link </a>

    function count(){

    // now ajax request to server to update count in db

    // simple ajax get request to php code here....

    return true;

    }

    since the function returns true, user will be taken to link and also before that hit counter code executes...
     
    mdrobiul, Nov 4, 2010 IP