Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8974999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:46:43+00:00 2026-06-15T18:46:43+00:00

I am executing the following query in a MySQL database (look at SELECT AND

  • 0

I am executing the following query in a MySQL database (look at SELECT AND WHERE, the rest is not important):

SELECT distinct fname //more fields...
FROM filedepot_files AS ff 
INNER JOIN filedepot_categories AS fc 
ON ff.cid = fc.cid 
INNER JOIN filedepot_access AS fa 
ON fc.cid = fa.catid 
WHERE fa.permid=$id AND fname LIKE '%$key%' 
ORDER BY DATE

The environment is a PHP script running under Drupal with FileDepot module but I doubt that matters at all.

This is the PHP script (well the part that matters):

$id = 1;
$key = $_GET['key'];
$query = .... (see above)
$result = db_query($query);
while($row = db_fetch_array($result)){
    //do stuff
    echo $row['fname'];
}

db_query() is a Drupal method that allows to easily execute SQL queries and a returns an array, db_fetch_array() allows to parse the result.

Now, DB contains the following entries for fname (there are more, these are just examples):

  • Dichiarazione 1
  • Dichiarazione 2
  • Guida 1
  • Guida 2

If I launch the script with “guida” as key it correctly returns the two entries both with PHP and MySQL.
If i use “Guida” it works as well.
However if I use “dichiarazione” it doesnt with PHP while it does with MySQL.
Strange thing is that “Dichiarazione” works both with PHP and MySQL.

What is wrong with the query? I tryed to use LOWER(fname) LIKE '%$key%' but it doesn’t seem to work as intended.

I am sure there is something stupid that I am missing but I can’t seem to find what that is…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:46:44+00:00Added an answer on June 15, 2026 at 6:46 pm

    % is a special character in Drupal queries (it’s used for placeholders). Try double-escaping it:

    WHERE fa.permid=$id AND fname LIKE '%%$key%%' 
    

    More worryingly though, you’re wide open to SQL injection. Some sanitisation is in order:

    ...
    WHERE fa.permid= %d AND fname LIKE '%%%s%%' 
    ...
    
    $query = db_query($sql, $id, $key);
    

    It might look crazy but that’s the right number of % signs. Two for each literal %, and one (%s) for the string placeholder

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm executing the following query SELECT COUNT(*) FROM table WHERE field1='value' AND (field2 >=
I'm executing the following query, to update the data in my database: mysql -u
I've been executing the following query in MySQL console: INSERT INTO pixel_window SELECT id
i have the following MySQL-Query: $sql = SELECT `eid` FROM `._ST_EVENT.` WHERE `tid` =
I'm building an application in Java to retrieve data from MySQL database. After executing
The following query is not executing and I am stumped as to why. The
I have the following MySQL query, which produces the result I want: SELECT `l`.`status`,
I'm executing the following query: if (isset ($_POST['valider']) ){ $password=$_POST['password']; $login=$_POST['login']; $sql ='SELECT *
I have the following query, courtesy of SO: SELECT field_website_value FROM field_data_field_website WHERE field_website_value
while executing the following query, i get an error that there's an error in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.