EPCtech Posted April 14, 2009 Share Posted April 14, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/153948-file-listing-does-not-work/ Share on other sites More sharing options...
.josh Posted April 14, 2009 Share Posted April 14, 2009 column names spelled right, capitalization correct? Quote Link to comment https://forums.phpfreaks.com/topic/153948-file-listing-does-not-work/#findComment-809114 Share on other sites More sharing options...
EPCtech Posted April 14, 2009 Author Share Posted April 14, 2009 I just finished triple-checking. Quote Link to comment https://forums.phpfreaks.com/topic/153948-file-listing-does-not-work/#findComment-809119 Share on other sites More sharing options...
.josh Posted April 14, 2009 Share Posted April 14, 2009 you sure it's the query string's fault? have you tried running it directly in your db? Quote Link to comment https://forums.phpfreaks.com/topic/153948-file-listing-does-not-work/#findComment-809121 Share on other sites More sharing options...
EPCtech Posted April 14, 2009 Author Share Posted April 14, 2009 I tried. The user I am testing with has 1 file. The first file is listed, but then he also gets 3 other submissions that were uploaded by someone else. Quote Link to comment https://forums.phpfreaks.com/topic/153948-file-listing-does-not-work/#findComment-809122 Share on other sites More sharing options...
.josh Posted April 14, 2009 Share Posted April 14, 2009 how about wrapping some parenthesis around all those OR conditions Quote Link to comment https://forums.phpfreaks.com/topic/153948-file-listing-does-not-work/#findComment-809124 Share on other sites More sharing options...
EPCtech Posted April 14, 2009 Author Share Posted April 14, 2009 I tried. Same result. But I did noticed one thing: It lists all files with the conditions. It completely drops the 'AND user=""' statement. Quote Link to comment https://forums.phpfreaks.com/topic/153948-file-listing-does-not-work/#findComment-809127 Share on other sites More sharing options...
.josh Posted April 14, 2009 Share Posted April 14, 2009 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') Quote Link to comment https://forums.phpfreaks.com/topic/153948-file-listing-does-not-work/#findComment-809144 Share on other sites More sharing options...
xtopolis Posted April 14, 2009 Share Posted April 14, 2009 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') Quote Link to comment https://forums.phpfreaks.com/topic/153948-file-listing-does-not-work/#findComment-809145 Share on other sites More sharing options...
.josh Posted April 14, 2009 Share Posted April 14, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/153948-file-listing-does-not-work/#findComment-809149 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.