c-o-d-e Posted November 23, 2009 Share Posted November 23, 2009 $query = mysql_error("UPDATE Users SET Used = YEAR(CURDATE()) WHERE username = '$username'") or trigger_error('Query failed: '. mysql_error()); If I have that, and lets say.. the users Used, is 2009. When this query takes place, would it bring an error, or would it replace the 2009 with 2009 anyway? If it would bring an error, how could I solve it. What this is suppose to do, is update the Used section with the current year, if it is not already set. Link to comment https://forums.phpfreaks.com/topic/182693-would-this-mysql_query-cause-an-error/ Share on other sites More sharing options...
Mchl Posted November 23, 2009 Share Posted November 23, 2009 It would not throw an error. I'm not sure whether it would actually update the row or not (one can check it by defining ON UPDATE CURRENT_TIMESTAMP column) Link to comment https://forums.phpfreaks.com/topic/182693-would-this-mysql_query-cause-an-error/#findComment-964246 Share on other sites More sharing options...
c-o-d-e Posted November 23, 2009 Author Share Posted November 23, 2009 It it sets the year as 2009, when 2010 comes, and that query is used, would it update it as its a new value? Link to comment https://forums.phpfreaks.com/topic/182693-would-this-mysql_query-cause-an-error/#findComment-964249 Share on other sites More sharing options...
peterg0123 Posted November 23, 2009 Share Posted November 23, 2009 I believe it will just update the column with current year as there are no other conditions. When you "if it is not already set", what would it be if not set? because you could check ..."WHERE username = '$username' AND Used < YEAR(CURDATE())". Link to comment https://forums.phpfreaks.com/topic/182693-would-this-mysql_query-cause-an-error/#findComment-964259 Share on other sites More sharing options...
c-o-d-e Posted November 23, 2009 Author Share Posted November 23, 2009 Default, when a user signs up. It will be NULL. As they login, it'll set the current year. When next year comes, for those who haven't logged in, it'll set "Used" as the previous year anyway, as that was when it was last updated. Then when they login, it will update the Used section to 2010. Link to comment https://forums.phpfreaks.com/topic/182693-would-this-mysql_query-cause-an-error/#findComment-964274 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.