Note that there are some explanatory texts on larger screens.

plurals
  1. POphp is not updating my database
    primarykey
    data
    text
    <p>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 :</p> <pre><code>&lt;?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; ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload