-1

What I want to achieve is to add 30 days to a customers subscription if the payment has been made

So I am using this code

$set = "REPLACE into CLIENTS where USR_PAID = '1' and USR_EXPIRATION = DATE(DATE_ADD(NOW(), INTERVAL 0 DAY)) values ('USR_EXPIRATION','" . $due . "')";
$update = $conn->update($set, $db);

I am getting the following syntax 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 'where USR_PAID = '1' and USR_EXPIRATION = DATE(DATE_ADD(NOW(), INTERVAL 0 DAY)) values ' at line 1 Statement: REPLACE into CLIENTS where USR_PAID = '1' and USR_EXPIRATION = DATE(DATE_ADD(NOW(), INTERVAL 0 DAY)) values ('USR_EXPIRATION', '09-05-2013')

I should tell you that I am using the same function to update the db in different parts of the website and is working just fine.

Also the following query is working and gives me all the clients that have paid and expire today:

$request = "select * from CLIENTS where USR_PAID = '1' and USR_EXPIRATION = DATE(DATE_ADD(NOW(), INTERVAL 0 DAY))";
$result = $conn->query($request, G_NORMDB);

I guess it is only a syntax error that I can't figure out.

4

3 回答 3

1

您的 REPLACE 语法错误。价值观,然后在哪里。

$set = "REPLACE into CLIENTS (the two columns here) VALUES ('USR_EXPIRATION','" . $due . "') where USR_PAID = '1' and USR_EXPIRATION = DATE(DATE_ADD(NOW(), INTERVAL 0 DAY))";

在此处阅读有关输入链接描述的更多信息以获取更多信息。

编辑:我很好奇没有在文档中看到 WHERE。根据这个答案,REPLACE 没有 WHERE 子句。请改用 UPDATE。

于 2013-08-06T13:07:19.460 回答
1

附带说明一下,我认为这无论如何都行不通,您不能replace into用来选择性地更改列。

这是手册的解释:

所有列的值均取自 REPLACE 语句中指定的值。任何缺失的列都设置为其默认值,就像 INSERT 一样。您不能引用当前行中的值并在新行中使用它们。

因此,您可以考虑包括整个用户行。

我认为使用这个查询更容易:

$q = "UPDATE CLIENTSSET USR_EXPIRATION= '$due' WHERE `USR_PAID = '1' AND USR_EXPIRATION = DATE(DATE_ADD(NOW(), INTERVAL 0 DAY))"; $update = $conn->update($q, $db);

让我知道这对你有什么用,如果有的话。

于 2013-08-06T13:11:41.127 回答
-1

如何遵循错误消息中的建议 - 检查有关REPLACE 查询语法的 Mysql 手册?

于 2013-08-06T13:06:12.023 回答