【发布时间】:2016-05-20 15:38:33
【问题描述】:
我有这两张表:
// users
+----+-------+-----------------------+--------+
| id | name | email | active |
+----+-------+-----------------------+--------+
| 1 | peter | peter12@hotmail.com | NULL |
| 2 | jack | most_wanted@gmail.com | NULL |
| 3 | john | john_20016@yahoo.com | NULL |
+----+-------+-----------------------+--------+
// activate
+----+---------+---------------------+
| id | post_id | random_string |
+----+---------+---------------------+
| 1 | 2 | fewklw23523kf |
+----+---------+---------------------+
我也有这样的网址:
http://example.com/activate.php?str=fewklw23523kf
我正在尝试做的所有事情:
- 将
GET['str']与random_string表中的random_string列进行比较 - 检查
active列中的NULL,其中id = post_id。
然后(如果有匹配的行)从users 表中设置1 的active 列。我该怎么做?
$str = $_GET['str'];
$stm = $db_con->prepare( "UPDATE users SET active = 1
WHERE ( SELECT 1 FROM activate WHERE random_string = ? ) t AND
( SELECT 1 FROM users WHERE t.post_id = id AND
active IS NULL ) ");
$stmt->execute(array($str));
我的查询没有按预期工作。
【问题讨论】: