如何检查表行是否存在以及是否存在行?到目前为止,我有这个:检查MySQL行是否存在
$id = $user->getID();
$username = $user->username;
$check = "SELECT id FROM users WHERE nickname = '".$username."'";
$result = mysql_query($check);
if(mysql_num_rows($result)){
$user->parent->mysql->query("INSERT INTO $ngtable (`id`, `namecolor`, `glowcolor`, `bubblecolor`, `bubbletext`, `bubbleglow`, `ringcolor`, `snowglow`) VALUES ('".$id."','0x','0x','0x','0x','0x','0x','0x')");
}else{
$user->parent->mysql->query("UPDATE $ngTable SET namecolor = '0x" . $arg . "' WHERE id = '" . $user->getID() . "'");
$user->sendPacket("%xt%sm%-1%0%$user->username, your name color is now: $arg%");
}
我相信你想翻转你'如果/ else'块,因为当'如果( mysql_num_rows($ result))'== true,id存在于用户中,所以你想要做更新,否则id在用户中不存在,所以你需要做一个插入? – Sean
如果ID不在表中,我希望MySQL插入它,如果它在表中它应该更新 – FrostyGamer150