I know there are already some posts about it, but I got other solution than others:
$sql= 'SELECT * FROM pr_users WHERE nick = :nick ';
$sqldot = $db->prepare($sql);
$checkif = $sqldot->execute(array(':nick' => $nick));
if (count($checkif) == 1) {
$_SESSION['ng'] = "<p class=\"text-warning\">Nickname already exists!</p>";
header("location: ../register.php");
} else {
$final++;
$_SESSION['nick'] = $nick;
}
$db is defined here:
$db = new PDO(
"mysql:host=" .dbserver. ";dbname=" .dbname,dbuser,dbpass,
array(
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8",
PDO::MYSQL_ATTR_INIT_COMMAND => "SET CHARACTER SET utf8"
)
);
I count if $checkif has any characters in, but for some reason even if "name" does not exist -> $checkif
still has some characters in, so it tells me that it already exist, which is wrong.