开发者

MySQL query being performed when PHP if condition not met?

开发者 https://www.devze.com 2022-12-23 03:28 出处:网络
The script I\'m using is if($profile[\'username\'] == $user[\'username\']) { $db->query(\"UPDATE users SET newcomments = 0 WHERE username = \'$user[username]\'\");

The script I'm using is

if($profile['username'] == $user['username']) {
    $db->query("UPDATE users SET newcomments = 0 WHERE username = '$user[username]'");
    echo "This is a test";
}

(Note that $db->query is exactly the same as mysql_query)

For some very odd reason, the MySQL query is being performed even if the defined condition is false

The "开发者_StackOverflow中文版This is a test" works properly and only appears when the condition is met, but the MySQL query is performed anyway

Whats the problem with it?


Typically the answer to such questions is somewhere else. Maybe similar SQL code is called elsewhere?


Your code looks fine. Try:

echo "<pre>";
print_r($profile);
print_r($user);

and see if it is what you expected.


I'm having trouble believing this, either way try something like this.

$query="";
if($profile['username'] == $user['username']) {
    $query ="UPDATE users SET newcomments = 0 WHERE username = '" . $user[username] . "' "; 
    echo "This is a test";
}

echo $query;
$db->query($query);
0

精彩评论

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

关注公众号