I get the error: Column \'Time\' cannot be null when using the query below, it works fine the first time when there is no duplicate but then when trying to update again I get th
It should be:
mysql_query("
INSERT INTO
$table(Username, `Time`, Videos, Credits)
VALUES
('$user', '$time', '$videos', '$credits')
ON DUPLICATE KEY UPDATE
Time = DATE_ADD(IFNULL(`Time`,now()),INTERVAL '$time' SECOND)
,Videos = Videos+'$videos'
,Credits = Credits+'$credits'
",
$conn
);
Don't forget to put single quotes around all injected variables, otherwise mysql_real_escape_string
will not protect you.
See:
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-add
If there's no duplicate, then this query will do an insert, and the Time
value will be null, as no value was ever set. Null + anything
is null, hence the error.
Try ... Time = COALESCE(Time, 0) + INTERVAL $time SECOND
or similar to get aroun dit.