title: Store number of clicks in database using php
body: <blockquote>
  <p>I am working on a project which includes image gallery.Now I want to store number of clicks/counts value into my database(developed in MySQL). I tried to do it in my own way, but problem is count/clicks value for all the images are stored in the database as same value.</p>
  <p>The code given below is in the file <strong>main.php</strong> which displays images that is retrieved from database.The <strong>picture.php</strong> is the one that retrieves images from database. I have appended the code to count the number of clicks in <strong>picture.php</strong> so that it counts whenever the image is clicked.</p>
  </blockquote>
  <p><strong>main.php</strong></p>
  <pre><code>    $query=&quot;SELECT * FROM files&quot;;
      $result=mysql_query($query) or die(mysql_error());
      while($fetch=mysql_fetch_array($result)){
           echo &quot;&lt;div class=single&gt;
                 &lt;div class=wrap&gt;
                     &lt;a href=picture.php?fid=&quot;.$offer_id.&quot;&gt;
                         &lt;img src=picture.php?fid=&quot;.$offer_id.&quot;\&quot;&gt;
                     &lt;/a&gt;
                 &lt;/div&gt;
                 &lt;/div&gt;&quot;;
      }
  </code></pre>
  <p><strong>picture.php</strong></p>
  <pre><code>    if(isset($_GET['fid']))
      {
           include &quot;connect.php&quot;;
           $fid=$_GET['fid'];
           $query=&quot;SELECT * FROM offers_em WHERE o_id =$fid&quot;;
           $result=mysql_query($query) or die(mysql_error());
  
           $sql=&quot;UPDATE offers_em SET count+=1 WHERE o_id=&quot;.$fid;
           $sql2=mysql_query($sql);
           
           $name=mysql_result($result,0,&quot;pic_name&quot;);
           $size=mysql_result($result,0,&quot;size&quot;);
           $type=mysql_result($result,0,&quot;type&quot;);
           $content=mysql_result($result,0,&quot;content&quot;);
     
           header(&quot;Content-Disposition: attachment; filename=$name&quot;);
           header(&quot;Content-length: $size&quot;);
           header(&quot;Content-type: $type&quot;);
           echo $content;
      }
      else{
           die(&quot;No file ID given...&quot;);
      }
  </code></pre>