开发者

PHP mysql query code not working

this code is not working why :(

$id = $temp['curchar'];
$data=strtotime(date('Y-m-d H:i:s'))+30; //+30 seconds to unix time
mysql_query("UPDATE `chars` SET data='$data' WHERE id='$id'");

Warning: mysql_error(): supplied argument is not a valid MySQL-Link resource in C:\Program Files\WebServ\httpd\world_1开发者_运维问答\char_info_slow.php on line 23


too many questions, you probably can start by checking

  1. how you connect to mysql?
  2. what is the column type for data?
  3. is $id match any record in table?
  4. how to verify are the matched records get updated?
  5. if your account connect to mysql allow to do write?

ps:

$data=strtotime(date('Y-m-d H:i:s'))+30; <-- wordless ...

$data = time()+30;

pps:

at least, you should try

$sql = "UPDATE `chars` SET data='$data' WHERE id='$id'";
mysql_query($sql) or trigger_error(mysql_error()." in ".$sql);


There's no reason to generate a date in PHP just to do some date arithmetic in MySQL. You can do this far easier within mysql as is:

UPDATE chars
SET data=DATE_ADD(data, INVERVAL 30 SECOND)
WHERE id=$id

Of course, this assumes you've made data a datetime type field. If it's just an int, then why bother with all the date math, and just do data=data+30.

As well, you're generating your time value in a highly inefficient manner. You format the current date as a string, convert that string to a number, and add 30 to it. Why not just do

$data = time() + 30;

instead? time returns the current date/time as a single integer (a unix timestamp), saving you the round trip through String Land.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜