Well, my question is: How can I be checking to see if there is already such a value in the database?
I have this code here that is already done the verification by the same SQL Query, that is if there is no such value it inserted and if it exists it did not insert, This is working perfectly.
$sql = 'INSERT INTO usuarios(nome,apelido)
SELECT "'.$valor[0].'", "'.$valor[1].'"
FROM DUAL
WHERE NOT EXISTS(SELECT nome,apelido FROM usuarios
WHERE nome = "'.$valor[0].'" OR apelido = "'.$valor[1].'")';
$resultado = $MySQLi->query($sql) OR trigger_error($MySQLi->error, E_USER_ERROR);
if($resultado == 1) {
echo 'sucesso';
} else {
echo 'já existe esse nome ou nick';
}
The problem is to receive this notification and tell the user if it already exists, because it always returns 1 in the $ result variable so I can not tell the user if it was entered or if the value already exists.
Could someone tell me a functional way to do this check?