我认为这应该在理论上有效。会吗?
$sql = "UPDATE users SET credtis = credits+1 WHERE id=echo .($_COOKIE['credits_id']!='');";
if ( !($result = $db->sql_query($sql)) ) {
message_die(GENERAL_ERROR, 'Could not update users table', '', __LINE__, __FILE__, $sql);
}
答案 0 :(得分:1)
由于多种原因,您的语法很糟糕。试试这样:
$id = (!empty($_COOKIE['credits_id']) ? (int) $_COOKIE['credits_id'] : 0;
$sql = "UPDATE users SET credtis = credits+1 WHERE id={$id}";
if (!($result = $db->sql_query($sql))) {
message_die(GENERAL_ERROR, 'Could not update users table', '', __LINE__, __FILE__, $sql);
}
另外,我假设message_die()
是您正在使用的某个框架或API的一部分,或者是您的自定义函数。否则,正确的函数是die()
,它不会接受所有这些参数。
答案 1 :(得分:0)
你的语法不好:P
我纠正了它:
$sql = "UPDATE users SET credits += 1 WHERE id='" . (isset($_COOKIE['credits_id']) && !empty($_COOKIE['credits_id']) ? $_COOKIE['credits_id'] : 0) . "'";
这是一个更简单的版本:
$credits_id = 0;
if (isset($_COOKIE['credits_id']) && !empty($_COOKIE['credits_id']))
$credits_id = (int) $_COOKIE['credits_id'];
$sql = "UPDATE users SET credits += 1 WHERE id='" . $credits_id . "'";
查看!=部分,是否要在未设置cookie时返回值?
PS:
根据“hoi”,你是荷兰人吗?