Niccaman Posted May 20, 2009 Share Posted May 20, 2009 i am querying this via php: INSERT INTO `restrictions` (`userid`,`enforcer`,`topics`, `posts`, UNIX_TIMESTAMP(`timeout`)) VALUES ('1','1','1', '1', '1243879972') I get this error when i check "mysql_error()": You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(`timeout`)) VALUES ('1','1','1', '1', '1243880105')' at line 1 Why?? Quote Link to comment https://forums.phpfreaks.com/topic/158953-mysql-statement/ Share on other sites More sharing options...
wildteen88 Posted May 20, 2009 Share Posted May 20, 2009 Your calling the MySQL function UNIX_TIMESTAMP within your field list clause. This is not possible. What are you trying to do? Quote Link to comment https://forums.phpfreaks.com/topic/158953-mysql-statement/#findComment-838319 Share on other sites More sharing options...
radi8 Posted May 20, 2009 Share Posted May 20, 2009 Well, I am not sure but it appears as though you are putting the UNIX_TIMESTAMP in the wrong place. I would try: $date = UNIX_TIMESTAMP($someDate); INSERT INTO `restrictions` (`userid`,`enforcer`,`topics`, `posts`, `timeout`) VALUES ('1','1','1', '1', $date) Quote Link to comment https://forums.phpfreaks.com/topic/158953-mysql-statement/#findComment-838323 Share on other sites More sharing options...
Niccaman Posted May 20, 2009 Author Share Posted May 20, 2009 Well what im trying to do is exact a date that could be either/and - days/hours/mins from NOW(). A user will select how many days/hours/mins or combination. I calculate the exact time in seconds, then add it to the php time() function which i believe is the equivalent time structure of UNIX_TIMESTAMP(). so if i convert the timestamp column to this format i can easily add the extra seconds. I have done this before, just not when entering a new row, but when: "SELECT UNIX_TIMESTAMP(`date`) FROM..." I need to enter information in the form of seconds. How do i allow my timestamp column to accept this? Quote Link to comment https://forums.phpfreaks.com/topic/158953-mysql-statement/#findComment-838330 Share on other sites More sharing options...
wildteen88 Posted May 20, 2009 Share Posted May 20, 2009 You cant call functions on field names for an insert statement (only for select). You can call MySQL functions for field values though. INSERT INTO `restrictions` (`userid`,`enforcer`,`topics`, `posts`, `timeout`) VALUES ('1','1','1', '1', UNIX_TIMESTAMP()) Quote Link to comment https://forums.phpfreaks.com/topic/158953-mysql-statement/#findComment-838337 Share on other sites More sharing options...
Niccaman Posted May 20, 2009 Author Share Posted May 20, 2009 Ok, i'll scrub my old plan. (I dont understand how to use whatever last post demonstrates.) Can anyone tell me how i would enter a timestamp which is for example: 12 days, 5 hours, 10 mins from current time? Thankyou in advance. Quote Link to comment https://forums.phpfreaks.com/topic/158953-mysql-statement/#findComment-838344 Share on other sites More sharing options...
wildteen88 Posted May 20, 2009 Share Posted May 20, 2009 In PHP you can do $time = strtotime('+12 Days 5 Hours 10 Minutes'); $sql = "INSERT INTO `restrictions` (`userid`,`enforcer`,`topics`, `posts`, `timeout`) VALUES ('1','1','1', '1', $time)"; mysql_query($sql); That will insert the timestamp for 12 Days, 5 Hours and 10 Minutes from now. Quote Link to comment https://forums.phpfreaks.com/topic/158953-mysql-statement/#findComment-838355 Share on other sites More sharing options...
Niccaman Posted May 20, 2009 Author Share Posted May 20, 2009 Thankyou for trying. The code you gave doesn't seem to be working though. The column value still reads: '00-00-0000 00:00:00' Quote Link to comment https://forums.phpfreaks.com/topic/158953-mysql-statement/#findComment-838370 Share on other sites More sharing options...
BobcatM Posted May 20, 2009 Share Posted May 20, 2009 Post what you have. Quote Link to comment https://forums.phpfreaks.com/topic/158953-mysql-statement/#findComment-838381 Share on other sites More sharing options...
Niccaman Posted May 20, 2009 Author Share Posted May 20, 2009 INSERT INTO `restrictions` (`userid`,`enforcer`,`topics`, `posts`, `messages`, `timeout`) VALUES ('1','1','1', '1', '1', '1243903362') I query it with no errors. I just realised that srttime function thing caused the same effect as the one which i scrubbed earlier. The problem is that its a "timestamp" column. This is why i tried to use UNIX_TIMESTAMP earlier. Anyway, is there anyway i can convert my seconds into a timestamp format???? or perhaps when i have my raw values of days/mins/hours, can i convert into timestamp format??? Quote Link to comment https://forums.phpfreaks.com/topic/158953-mysql-statement/#findComment-838392 Share on other sites More sharing options...
fenway Posted May 22, 2009 Share Posted May 22, 2009 Yup... FROM_UNIXTIME(). Quote Link to comment https://forums.phpfreaks.com/topic/158953-mysql-statement/#findComment-840123 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.