fry2010 Posted February 26, 2009 Share Posted February 26, 2009 Ok what i have done so far is: create a registered user. When they register I use this to store the date they signed up: $result = $conn2->query("UPDATE useraccount SET joined = CURDATE() WHERE username = '$user'"); This works correctly. Ok so now I want to add 7 days to this date and insert it in 'expire' column. I want to do this at the same time that they join. I know that I could do this with about 3 seperate database queries but id rather do it with just one, or even two at most. I have tried this: $result = $conn2->query("UPDATE useraccount SET joined = CURDATE(), expire = DATEADD(CURDATE(),INTERVAL 7 DAYS) WHERE username = '$user'"); But it doesnt work. I have also tried it with NOW(). Link to comment https://forums.phpfreaks.com/topic/146958-solved-how-to-insert-dateadd-into-column/ Share on other sites More sharing options...
fry2010 Posted February 26, 2009 Author Share Posted February 26, 2009 Ok I managed to sort this out also. I used this for anyone else thats stuck on it: $result = $conn2->query("UPDATE useraccount SET joined = CURDATE(), expire = DATE_ADD(joined, INTERVAL 7 DAY) WHERE username = '$user'"); Also the original problem from where all this started for me was because I was using PDO prepare and execute method for querying the date. But you cant do this because PDO will automatically quote out the input, so mysql will read it as a string, not a function. Luckily my data isnt used from a user input form, so i can just use the standard query method. I hate to have to do stuff when people put dates in a form. I have a new problem now though. for anyone that sees this and can offer help I will be posting it in the php part as it relates to that. Link to comment https://forums.phpfreaks.com/topic/146958-solved-how-to-insert-dateadd-into-column/#findComment-771507 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.