Possible Duplicate:
php - check record exists db - error show
I am currently trying to add a user to the database. I want to to check if the user exists, and IF SO, then just update a few fields. If IT DOESNT, then it should completely insert a new record.
$result22 = mysql_query("SELECT COUNT(1) FROM newsite WHERE user = '$username'");
if($result22){
$SQL = "UPDATE newsite SET active = '1' WHERE user = '$username'";
$_SESSION['username'] = $_GET['user'];
$result = mysql_query($SQL);
echo("lol."); // TEST
header("Location: ./share.php?user=$username");
}
if(!$result22){
$SQL = "INSERT INTO newsite (user, active) VALUES ('".$username."', '1')";
$_SESSION['username'] = $_GET['user'];
$result = mysql_query($SQL);
echo("NOPE."); //TEST
header("Location: ./share.php?user=$username");
}
}
I'm not really sure why, but no matter what it ALWAYS outputs "lol." (aka, the user exists.) it completely ignores the other if.