MyBB Community Forums

Full Version: Usernames with Spaces Don't Return in DB Object
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm having a problem where if the user has a space in their name, it doesn't return in the MyBB $db object when searching for them via SQL by their username.

for example:

$query = $db->simple_select('users', 'uid, username', "username IN({$userNames})");

Returns 0 for usernames with spaces.

For example if the username is a Rec

query = username IN('a Rec')

the Result is:
mysqli_result Object
(
[current_field] => 0
[field_count] => 2
[lengths] =>
[num_rows] => 0
[type] => 0
)


I can't understand why this happe
ns. Running the same query in PHPMYADMIN works perfectly.

Anybody can shine a light on this? It works great if the username has no space.
Perhaps this?

$query = $db->simple_select('users', 'uid, username', "username IN(`a Rec`)");
(2015-08-30, 08:12 AM)Sazze Wrote: [ -> ]Perhaps this?

$query = $db->simple_select('users', 'uid, username', "username IN(`a Rec`)");


Thank you!!

the backticks don't work unfortunately, I think they are reserved for columns.

Reading up on it does seem that it may lead me to the right direction. Let me do some tests.

So i think I solved it. I have to escape the white space with a '%' or it won't return anything.

I'm doing more tests then this can be marked as resolved.
(2015-08-31, 07:19 AM)freewill Wrote: [ -> ]So i think I solved it. I have to escape the white space with a '%' or it won't return anything.

Use %20 for spaces.
(2015-08-31, 12:17 PM)Ad Bakker Wrote: [ -> ]
(2015-08-31, 07:19 AM)freewill Wrote: [ -> ]So i think I solved it. I have to escape the white space with a '%' or it won't return anything.

Use %20 for spaces.


Why?

That's URL encoding. I don't think that would return anything. Whereas the % in MYSQL would account for any character in between (a wild card).