Jump to content

mysql statement


Niccaman

Recommended Posts

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??

Link to comment
https://forums.phpfreaks.com/topic/158953-mysql-statement/
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/158953-mysql-statement/#findComment-838330
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/158953-mysql-statement/#findComment-838337
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/158953-mysql-statement/#findComment-838355
Share on other sites

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???

Link to comment
https://forums.phpfreaks.com/topic/158953-mysql-statement/#findComment-838392
Share on other sites

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.