sql - Php/PDO does user exist? -


i know there posts it, got other solution others:

    $sql= 'select * pr_users nick = :nick ';         $sqldot = $db->prepare($sql);         $checkif = $sqldot->execute(array(':nick' => $nick));          if (count($checkif) == 1) {             $_session['ng'] = "<p class=\"text-warning\">nickname exists!</p>";             header("location: ../register.php");         } else {             $final++;             $_session['nick'] = $nick;         } 

$db 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 characters in, reason if "name" not exist -> $checkif still has characters in, tells me exist, wrong.

execute function returns true on success or false on failure. if condition if (count($checkif) == 1) true.

you need fetch results after execute() , check count results.

$checkif = $sqldot->execute(array(':nick' => $nick)); $result = $sqldot->fetch();    if (!empty($result)) {         $_session['ng'] = "<p class=\"text-warning\">nickname exists!</p>";         header("location: ../register.php");     } else {         $final++;         $_session['nick'] = $nick;     } 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -