Jump to content

Would this MySQL_Query cause an error?


c-o-d-e

Recommended Posts

$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

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())".

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.