Update a counter when a link is clicked

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ian Davies

    Update a counter when a link is clicked

    Hello

    I have seen some tutorials to put a update a counter field in a record. I
    have the counter field in a table that also has a field for a path to file.

    I display the records in a table on a web page e.g.

    IndexNo ............Tit le............. ............... .... Link
    ............... ............... ...... Count
    ......1........ .....MyFileName ........www.mysite/files/MyFileName.doc........
    ......0
    etc

    User can click on the Link field in the table to download the file.

    The problem is I can't find a way that will run an update query along the
    lines of

    $Query = mysql_query("UP DATE Resources SET Count = Count + 1 WHERE IndexNo
    = '$IndexNo');

    when the user clicks the link

    Can anyone suggest a way or direct me to a tutorial

    Thanks
    Ian



  • Erwin Moller

    #2
    Re: Update a counter when a link is clicked

    Ian Davies wrote:
    [color=blue]
    > Hello
    >
    > I have seen some tutorials to put a update a counter field in a record. I
    > have the counter field in a table that also has a field for a path to
    > file.
    >
    > I display the records in a table on a web page e.g.
    >
    > IndexNo ............Tit le............. ............... .... Link
    > ............... ............... ..... Count
    >[/color]
    ......1........ .....MyFileName ........www.mysite/files/MyFileName.doc........[color=blue]
    > .....0
    > etc
    >
    > User can click on the Link field in the table to download the file.
    >
    > The problem is I can't find a way that will run an update query along the
    > lines of
    >
    > $Query = mysql_query("UP DATE Resources SET Count = Count + 1 WHERE
    > IndexNo
    > = '$IndexNo');
    >
    > when the user clicks the link
    >
    > Can anyone suggest a way or direct me to a tutorial
    >
    > Thanks
    > Ian[/color]

    Hi,

    Your question is very clear, but if I understand right, this may help:

    1) Make a link to a increasecounter .php and add the filename:
    <a href="increasec ounter.php?file name=MyFileName .doc">

    2) In increasecounter .php:
    $filename = $_GET["filename"];
    // do your update in the db here

    3) Redirect to the file
    header("Locatio n: MyFileName.doc" );
    exit;

    Regards,
    Erwin Moller

    Comment

    • Ian Davies

      #3
      Re: Update a counter when a link is clicked

      Thanks for your advice
      Your code was just what I was looking for
      It is updating the table with the counter but it is not bringing up the file
      to download any more

      The modified code is as follows

      <a href="increasec ounter.php?file name=<?php echo $Link; ?>"

      The $Link returns the full path to the file (from the same table as the
      count field)

      In my increase counter.php I have

      *************** *************** *********
      $filename = $_GET["filename"];
      echo $filename;
      $Query = mysql_query("UP DATE Resources SET count = count + 1 WHERE Link =
      '$filename'");
      header("Locatio n: $filename");
      exit;
      *************** *************** *********
      I put the echo in just to check the file name is correct
      which it is as it is used in the SQLs WHERE clause and it updates the record
      as I mentioned earlier
      But the file to download is not appearing. Can you see what is wrong
      The address in the browser window is as follows if it helps




      which appears to be wrong
      when the file was downloading previously the address would have been



      Any clues
      Thanks
      Ian

      "Erwin Moller"
      <since_humans_r ead_this_I_am_s pammed_too_much @spamyourself.c om> wrote in
      message news:44507887$0 $31652$e4fe514c @news.xs4all.nl ...[color=blue]
      > Ian Davies wrote:
      >[color=green]
      > > Hello
      > >
      > > I have seen some tutorials to put a update a counter field in a record.[/color][/color]
      I[color=blue][color=green]
      > > have the counter field in a table that also has a field for a path to
      > > file.
      > >
      > > I display the records in a table on a web page e.g.
      > >
      > > IndexNo ............Tit le............. ............... .... Link
      > > ............... ............... ..... Count
      > >[/color]
      >[/color]
      ......1........ .....MyFileName ........www.mysite/files/MyFileName.doc........[color=blue][color=green]
      > > .....0
      > > etc
      > >
      > > User can click on the Link field in the table to download the file.
      > >
      > > The problem is I can't find a way that will run an update query along[/color][/color]
      the[color=blue][color=green]
      > > lines of
      > >
      > > $Query = mysql_query("UP DATE Resources SET Count = Count + 1 WHERE
      > > IndexNo
      > > = '$IndexNo');
      > >
      > > when the user clicks the link
      > >
      > > Can anyone suggest a way or direct me to a tutorial
      > >
      > > Thanks
      > > Ian[/color]
      >
      > Hi,
      >
      > Your question is very clear, but if I understand right, this may help:
      >
      > 1) Make a link to a increasecounter .php and add the filename:
      > <a href="increasec ounter.php?file name=MyFileName .doc">
      >
      > 2) In increasecounter .php:
      > $filename = $_GET["filename"];
      > // do your update in the db here
      >
      > 3) Redirect to the file
      > header("Locatio n: MyFileName.doc" );
      > exit;
      >
      > Regards,
      > Erwin Moller
      >[/color]


      Comment

      • Ehsan

        #4
        Re: Update a counter when a link is clicked

        You cannot have anything printed before header(). Remove echo filename;
        and try running the script.

        Hope this helps.

        Thanks and God Bless!!

        Ehsan


        Comment

        • Ian Davies

          #5
          Re: Update a counter when a link is clicked

          Ehsan

          That was the problem
          Thanks

          Ian


          "Ehsan" <haque.ehsan@gm ail.com> wrote in message
          news:1146232615 .445214.12030@i 39g2000cwa.goog legroups.com...[color=blue]
          > You cannot have anything printed before header(). Remove echo filename;
          > and try running the script.
          >
          > Hope this helps.
          >
          > Thanks and God Bless!!
          >
          > Ehsan
          > http://ehsan.bdwebwork.com
          >[/color]


          Comment

          Working...