Jump to content

Recommended Posts

Hi,

In my site people submit games that they have created and let others download them. Anyways, you must upload the game first. And I want it to list the files. What is wrong with this SQL code?

 

SELECT file FROM myfiles WHERE file LIKE '%.zip' OR file LIKE '%.exe' OR file LIKE '%.gmk' OR file LIKE '%.gm6' OR file LIKE '%.gmd' OR file LIKE '%.rar' OR file LIKE '%.zip' AND user='".$name."'

Yes, $name is set.

 

Is there a problem with this code?

 

Thanks for any help,

En-Psyche

Link to comment
https://forums.phpfreaks.com/topic/153948-file-listing-does-not-work/
Share on other sites

so you tried:

SELECT file FROM myfiles WHERE (file LIKE '%.zip' OR file LIKE '%.exe' OR file LIKE '%.gmk' OR file LIKE '%.gm6' OR file LIKE '%.gmd' OR file LIKE '%.rar' OR file LIKE '%.zip') AND user='".$name."'

 

(except replacing user='".$name."' with user='somename')

I was going to suggest limiting by username first:

SELECT file FROM myfiles 
WHERE user='$name'
AND (file LIKE '%.zip' 
OR file LIKE '%.exe' 
OR file LIKE '%.gmk' 
OR file LIKE '%.gm6' 
OR file LIKE '%.gmd' 
OR file LIKE '%.rar' 
OR file LIKE '%.zip')

I don't think that should really matter.  the AND should get evaluated first regardless. But without the parenthesis, it's doing

 

file LIKE '%.zip' AND user='$name' which would evaluate false if it's not a zip file, but then it evaluates all the other ORs and they all come up positive without being filtered by the user.  Hence the parenthesis around all of the ORs, which will first evaluate all of them and then filter against the user. 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.