tags:

views:

77

answers:

3

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 "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?

A: 

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

naivists
But I tried removing that script, and then the query wasn't performed
Ryan
Do you know that the SQL statement executes successfully?
Brandi
Yeah, as well as temporarily adding "or die(mysql_error())" I also tested the code in PHPMyAdmin and it worked
Ryan
A: 

Your code looks fine. Try:

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

and see if it is what you expected.

luiscubal
A: 

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);
MindStalker