php - Why the script saves all the time the same data? -


i have problem php script system runs every minute.

my php-script this:

<?php $y = date("y", time()); $m = date("m", time()); $d = date("d", time()); $h = date("h", time());  mysql_connect("localhost", "root", ""); mysql_select_db("dashboard");  $check_date = mysql_query("select year,month,day serverstats year='".$y."' && month='".$m."' && day='".$d."'");  if(mysql_num_rows($check_date)==0) {     mysql_query("insert serverstats (year,month,day,h01,h02,h03,h04,h05,h06,h07,h08,h09,h10,h11,h12,h13,h14,h15,h16,h17,h18,h19,h20,h21,h22,h23,h24)         values (         '".$y."', '".$m."', '".$d."', null , null , null , null , null , null , null , null , null , null , null , null , null , null , null , null , null , null , null , null , null , null , null , null         );     ") or die(mysql_error()); } else {     $load = file_get_contents("/proc/loadavg");     $load = explode( ' ', $load );     $total_load = $load[0] + $load[1] + $load[2];      $last_load = mysql_query("select h".$h." serverstats");     $daten = mysql_fetch_array($last_load);     $total = $daten["h".$h.""]+$total_load;      mysql_query("update serverstats set h".$h."='".$total."'");     mysql_query("update serverstats set ts ='".time()."'"); }  ?> 

and database looks this: timestamp(ts) , other values same, did make wrong? enter image description here

you missing condition in update

update serverstats set ts ='".time()."'" 

while updating database should have clause .. sql should like\

update serverstats set ts ='".time()."' = 'your condition'" 

if miss where in update clause .. records updated ..

note please switch mysqli_* or pdo . mysql_* no longer officially maintained.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -