Using a literal "%" in a format (MySQL)
#1

Hey guys, I want to withdraw all accounts which contains the following entered name, I tried using '%%%e%%' and it didn't go well.
I used a regular format and inserted it into mysql format, here is my code
PHP код:
    format(stringsizeof(string), "%%%s%%"name);
    
mysql_format(mysqlquerysizeof(query), "SELECT `Username`, `Registration`, `IP`, `Score` FROM `Users` WHERE `Username` LIKE '%e' LIMIT %d"nameamount);
    print(
query); 
How can I solve this ?

Here is the query for the `name` - "erer":
Код:
SELECT `Username`, `Registration`, `IP`, `Score` FROM `Users` WHERE `Username` LIKE 'erer' LIMIT 2
Reply
#2

try doing dat sir:
PHP код:
mysql_escape_string(namestring); 
then
PHP код:
mysql_format(mysqlquerysizeof(query), "SELECT `Username`, `Registration`, `IP`, `Score` FROM `Users` WHERE `Username` LIKE '%%%s%%' LIMIT %d"stringamount); 
print(
query); 
however in your code you was formating string and using name instead of string .-.
Код:
format(string, sizeof(string), "%%%s%%", name); 
    mysql_format(mysql, query, sizeof(query), "SELECT `Username`, `Registration`, `IP`, `Score` FROM `Users` WHERE `Username` LIKE '%e' LIMIT %d", name, amount); 
    print(query);
its supposed to be:
PHP код:
format(stringsizeof(string), "%%%s%%"name); 
    
mysql_format(mysqlquerysizeof(query), "SELECT `Username`, `Registration`, `IP`, `Score` FROM `Users` WHERE `Username` LIKE '%e' LIMIT %d"stringamount); 
    print(
query); 
Reply
#3

Quote:
Originally Posted by jlalt
Посмотреть сообщение
try doing dat sir:
PHP код:
mysql_escape_string(namestring); 
then
PHP код:
mysql_format(mysqlquerysizeof(query), "SELECT `Username`, `Registration`, `IP`, `Score` FROM `Users` WHERE `Username` LIKE '%%%s%%' LIMIT %d"stringamount); 
print(
query); 
however in your code you was formating string and using name instead of string .-.
Код:
format(string, sizeof(string), "%%%s%%", name); 
    mysql_format(mysql, query, sizeof(query), "SELECT `Username`, `Registration`, `IP`, `Score` FROM `Users` WHERE `Username` LIKE '%e' LIMIT %d", name, amount); 
    print(query);
its supposed to be:
PHP код:
format(stringsizeof(string), "%%%s%%"name); 
    
mysql_format(mysqlquerysizeof(query), "SELECT `Username`, `Registration`, `IP`, `Score` FROM `Users` WHERE `Username` LIKE '%e' LIMIT %d"stringamount); 
    print(
query); 
Works smoothly mate, thank you
BTW, Escaping a string actually makes it longer or shorter ?
P.S Can't rep sorry
Reply
#4

Longer, 2 * <string to escape> + 1 in the worst case (all characters to be escaped).
Reply
#5

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Longer, 2 * <string to escape> + 1 in the worst case (all characters to be escaped).
Thank you
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)