Here is what I get if I use my first section of code:
SQL: [45] SELECT id FROM users WHERE username = ':name' Params: 8 Key: Name: [5] :name paramno=-1 name=[5] ":name" is_param=1 param_type=2 Key: Name: [5] :pass paramno=-1 name=[5] ":pass" is_param=1 param_type=2 Key: Name: [6] :email paramno=-1 name=[6] ":email" is_param=1 param_type=2 Key: Name: [7] :gender paramno=-1 name=[7] ":gender" is_param=1 param_type=2 Key: Name: [4] :age paramno=-1 name=[4] ":age" is_param=1 param_type=2 Key: Name: [9] :location paramno=-1 name=[9] ":location" is_param=1 param_type=2 Key: Name: [7] :avatar paramno=-1 name=[7] ":avatar" is_param=1 param_type=2 Key: Name: [11] :avatarSize paramno=-1 name=[11] ":avatarSize" is_param=1 param_type=2
And if I use the second set:
SQL: [39] SELECT id FROM users WHERE username = ? Params: 1 Key: Position #0: paramno=0 name=[0] "" is_param=1 param_type=2
@Misson: If I used the array_intersect_key() method you talked about, which two arrays would I be comparing? Would it be something like:
PHP Code:
$sth->prepare("... :name");
$sth->execute(array_intersect_key($info,something));
Also, was that the right way to do the :key? Or do I have to place ' 's around it to turn it into a string?
I.E.:
PHP Code:
$sth = $dbh->prepare("... WHERE username = :name");
Edit 1: I changed it a little bit, now I get a blank screen when I try.
PHP Code:
$info = array(
":name"=>$_POST['name'],
":pass"=>md5($_POST['password']),
":email"=>$_POST['email'],
":gender"=>$_POST['gender'],
":age"=>$_POST['age'],
":location"=>$_POST['location'],
":avatar"=>$_FILES['avatar']['name'],
":avatarSize"=>$_FILES['avatar']['size']);
#...
try {
$sth = $dbh->prepare("SELECT username FROM users WHERE username = ?");
$sth->execute(array($_POST['name']));
} catch(PDOException $e) {
$sth->errorInfo();
$sth->debugDumpParams();
writeError($e->getMessage(),CURPAGE);
}
if($sth->rowcount() > 0)
$error[] = "<b>Username is taken</b> ";