Jump to content

datetime error


Danny620

Recommended Posts

this should check how many hours the user as missed and credit them with moeny but the thing is when it puts the new update time in it stores it as

 

<?php session_start();

require('mysqli_connect.php');
$id = $_SESSION['id'];

	// Query the database:
	$q = "SELECT * FROM test WHERE id='$id'";		
	$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));
	$user = mysqli_fetch_array ($r, MYSQLI_ASSOC); 	
			mysqli_free_result($r);

		//money amount to add for each round
$add_money = 1000;
//time now, and round time in seconds (1h=60*60seconds=3600)
$time_now = time(); 
$round = 3600;

//time of last update+time needed must be smaller then time now to update
if (($user[lastupdate]+$round) <= $time_now) {
//see how many rounds (hours) were there from last update
$nr_rounds = floor(($time_now-$user[lastupdate])/$round);
//calculate how much money user gained
$all_money = $nr_rounds * $add_money;
//calculate how many rounds in seconds (how many hours in seconds)
$add_time = $nr_rounds * $round;

//lets update users table
$q = "UPDATE test SET lastupdate=lastupdate+'$add_time', money=money+'$all_money' WHERE id = '$user[id]'";
$r = mysqli_query($dbc, $q);
//here you can refresh page (so you can see progress) or select user again using login
}
?>

lastupdate

0000-00-00 00:00:00 it should be at date and time not that

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.