Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8539323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:20:18+00:00 2026-06-11T11:20:18+00:00

I have this php page, which suppose to display an image and then update

  • 0

I have this php page, which suppose to display an image and then update “download” row in database with 1 number for each visit, some times this works , and for some other pictures it’s not working, how can i fix this ? please take a look at my code if there’s something wrong :

<?php

include 'conf_global.php';

if ($_GET['id'])
{
    $id = $_GET['id'];
}
else
{
    die ("no id selected");
}

@ $db = mysql_pconnect($mysql['host'], $mysql['user'], $mysql['pass']) or die(mysql_error());
//IT"S NOT WORKING!
if (!$db)
{
    die("error");
}
mysql_select_db($mysql['db']) or die(mysql_error());

$query = "SELECT * FROM `images` WHERE id='" . $id ."'";

$result = mysql_query($query) or die(mysql_error());

if (!$result)
{
    die("MySQL Select error");
}

$num_results = mysql_num_rows($result);
if ($num_results ==0)
{
die("Image not found");
}

$row = mysql_fetch_array($result);
if ($id != 0)
{
    $downloads = $row['downloads'] + 1;

    $lastuse = time();

     $ss = mysql_query("select downloads from `images` where id='".$id."'") or die(mysql_error());
     $rr = mysql_fetch_array($ss);

    $query = "update `images` set downloads='".($rr['downloads']+1)."' where id='".$id."'";
    $result = mysql_query($query);
    if (!$result)
    {
        die("MySQL update error");
    }

    $query = "UPDATE `images` SET lastuse='" . $lastuse . "' WHERE id='". $id ."'";
    $result = mysql_query($query);
    if (!$result)
    {
        die("MySQL update error2");
    }

    //get current stats
    $query = "SELECT * FROM `stat_cache`";

    $result = mysql_query($query);

    if (!$result)
    {
        die("MySQL Select error");
    }
    $stat = mysql_fetch_array($result);

    //band update
    $bandwidth = $stat['band'] + $row['size'];
    $query = "UPDATE `stat_cache` SET band='" . $bandwidth . "' WHERE 1";
    $result = mysql_query($query);
    if (!$result)
    {
        die("MySQL Update error");
    }

    //downloads update
    $downloads = $stat['downloads'] + 1;
    $query = "UPDATE `stat_cache` SET downloads='" . $downloads . "' WHERE 1";
    $result = mysql_query($query);
    if (!$result)
    {
        die("MySQL Update error");
    }
}
//Lets create the image, now.
if(!file_exists('./uploads/' . $id)) {
    die("Image not found");
    exit;
}
header('Content-type: ' . $row['type']);

$fp = fopen('./uploads/' . $id, 'r');

$contents = fread($fp, $maxfilesize);
fclose($fp);

echo $contents;

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T11:20:19+00:00Added an answer on June 11, 2026 at 11:20 am

    Try this its working 🙂 you add wrong code

    <?php
    
    include 'conf_global.php';
    
    if ($_GET['id'])
    {
        $id = $_GET['id'];
    }
    else
    {
        die ("no id selected");
    }
    
    @ $db = mysql_pconnect($mysql['host'], $mysql['user'], $mysql['pass']) or die(mysql_error());
    //IT"S NOT WORKING!
    if (!$db)
    {
        die("error");
    }
    mysql_select_db($mysql['db']) or die(mysql_error());
    
    $query = "SELECT * FROM `images` WHERE id='" . $id ."'";
    
    $result = mysql_query($query) or die(mysql_error());
    
    if (!$result)
    {
        die("MySQL Select error");
    }
    
    $num_results = mysql_num_rows($result);
    if ($num_results ==0)
    {
    die("Image not found");
    }
    else {
        $row = mysql_fetch_array($result);
    
        $downloads = $row['downloads'] + 1;
    
        $lastuse = time();
    
         $ss = mysql_query("select downloads from `images` where id='".$id."'") or die(mysql_error());
         $rr = mysql_fetch_array($ss);
    
        $query = "update `images` set downloads='".($rr['downloads']+1)."' where id='".$id."'";
        $result = mysql_query($query);
        if (!$result)
        {
            die("MySQL update error");
        }
    
        $query = "UPDATE `images` SET lastuse='" . $lastuse . "' WHERE id='". $id ."'";
        $result = mysql_query($query);
        if (!$result)
        {
            die("MySQL update error2");
        }
    
        //get current stats
        $query = "SELECT * FROM `stat_cache`";
    
        $result = mysql_query($query);
    
        if (!$result)
        {
            die("MySQL Select error");
        }
        $stat = mysql_fetch_array($result);
    
        //band update
        $bandwidth = $stat['band'] + $row['size'];
        $query = "UPDATE `stat_cache` SET band='" . $bandwidth . "' WHERE 1";
        $result = mysql_query($query);
        if (!$result)
        {
            die("MySQL Update error");
        }
    
        //downloads update
        $downloads = $stat['downloads'] + 1;
        $query = "UPDATE `stat_cache` SET downloads='" . $downloads . "' WHERE 1";
        $result = mysql_query($query);
        if (!$result)
        {
            die("MySQL Update error");
        }
    }
    //Lets create the image, now.
    if(!file_exists('./uploads/' . $id)) {
        die("Image not found");
        exit;
    }
    header('Content-type: ' . $row['type']);
    
    $fp = fopen('./uploads/' . $id, 'r');
    
    $contents = fread($fp, $maxfilesize);
    fclose($fp);
    
    echo $contents;
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this PHP page where the user can select and un-select items. The
i have this simple code to load data from other php page using get
i have tried this code to redirect a php page.but it s not working
I have this jQuery script var dataString = class_id=+class_id; $.ajax({ type: POST, url: page.php,
I have this page: http://www.thedome.it/cmsms/index.php?page=alla-spina I'd like to send a newsletter to subscribers every
I have this htaccess rule to redirect my page to data_parser.php RewriteEngine On RewriteRule
I have a php page called form.php. When you go to this page it
I have a list menu in my php page. In this list menu i
I'm really struggling with this. I have a viewdetails.php page, addnew.php page and a
I have my site as localhost/tutorials/rewrite/news.php on this page are titles from news articles

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.