Im trying to write a function to check whether a user exists in a table, if so, update the row, if not, insert it.
Here is my function:
function UserExists($screenname){
$mysql = mysql_fetch_array ( mysql_query("SELECT * FROM `users` WHERE `screenname` = '$screenname' "));
if($mysql){
return TRUE;
}else{
return FALSE;
}
}
And im executing this function using the following:
if(UserExists($user)){
mysql_query("UPDATE `users` SET `token` = '$token' , `secret` = '$secret' WHERE `screenname` = '$user' ");
}else{
mysql_query("INSERT INTO `users` (`screenname`, `token`, `secret`) VALUES ('$user', '$token', '$secret')");
}
Its not doing anything, not throwing any errors, but also not updating the table.