MySQL query being performed when PHP if condition not met?
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);
精彩评论