Friends how do I tell mysql that if the data

exists not to add it?

I currently have it like this
function addPremiumUser($userID){
global $conn;

if(!$userData){
$addtodb = mysqli_query($conn,"SELECT userid FROM premium WHERE userid=$userID;");
logsummary("<b>❌ [LOG] New User Error - existing $userID</b>");
return True;
} else {
$addtodb = mysqli_query($conn,"INSERT INTO premium (userid, username) VALUES ('$userID', '$username')");
logsummary("<b>✅ [LOG] New User - $userID</b>");
returnFalse;
}
}
But although the data does not exist, I get that it already exists

4 ответов

12 просмотров

U need to set the condition after first query

.- Автор вопроса
M A
U need to set the condition after first query

There it is but it only enters the first condition and there it stays

In this way, u are running two queries U can use one query for insert if not exist https://stackoverflow.com/questions/1361340/how-can-i-do-insert-if-not-exists-in-mysql

Похожие вопросы

Карта сайта