Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Nooooooo case insensitive queries -.-
Old 08-14-2005, 07:35 PM Nooooooo case insensitive queries -.-
AxE
AxE's Avatar
Skilled Talker

Posts: 62
Trades: 0
Ive been working with PHP/MySQL for around a year now, never had this problem before.

Im working on an online text game type thing (yeah, I know, not original but im just brushing up my skills a bit.), for the login I use this query:

PHP Code:
$sql "SELECT `username`,`email`,`password`
FROM `tbl_members`
WHERE `username = '"
.$username."'"
Works fine! After that I do my query and checks etc. then set my session variables to exactly the specified username and a SHA1 of the password. If my account is "AxE", it logs in fine with "Axe", "axe", "AXE" etc.

But, here comes the strange part. In my header script for the game area (as in, a script that is included right at the top of each page) I do:

PHP Code:
$username addslashes($_SESSION['username']);
$password $_SESSION['password']; //This is in SHA1 encryption, just like in the database.
$sql "SELECT *
FROM `tbl_members`
WHERE `username` = '"
.$username."'"
Now, if my account name is "AxE", and I logged in with "AxE", works fine! No problems. But. Always a but. But, If I login with the username "Axe" or "axe", it gets past the login no problem, then, gets to the game area and tells me that my username is incorrect. I did a print_r($_SESSION) in my game headers, got the SHA1 of the password, checked it against the SHA1 of the password in the database, its the same, so that cant be the problem. I get my username, check it against the username in the database and its the same, except for the case.



Does anyone know why my queries are being picky suddenly? Is there anyway to do case sensitive quries? If so, ill just make the login case sensitive.



Thanks,
Your friendly neighbour-hood bashing tool, AxE.
AxE is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-14-2005, 08:53 PM
asm
Extreme Talker

Posts: 217
Location: UK.Lancashire(true)
Trades: 0
well you learn something new every day!! anyways have you read this

http://dev.mysql.com/doc/mysql/en/case-sensitivity.html

to be honest it didnt seem much help other than saying there is a bit of work involved.
asm is offline
Reply With Quote
View Public Profile Visit asm's homepage!
 
Old 08-15-2005, 12:33 AM
AxE
AxE's Avatar
Skilled Talker

Posts: 62
Trades: 0
Nope, I hadnt read it until now. I searched around the MySQL site but god, that site is so hard to find what you want :\ searches are hardly releveant unless its a direct function search, Ive found.

Anyway, So basically theres no actual reason why my query is being **** annoying? Im using standard english characters, nothing foreign. If not, then ill have a look at the binary queries.
AxE is offline
Reply With Quote
View Public Profile
 
Old 08-15-2005, 01:07 AM
AxE
AxE's Avatar
Skilled Talker

Posts: 62
Trades: 0
Oh, Bugger!

I found out what was wrong, it wasnt my SQL query at all, though I assumed it was. I did a little more testing, and found out when it said that I wasnt actually logged in due to the case sensitivity, the query did actually find and return my account! So, I did a few more tests, and found out eventually it was because I was doing:

PHP Code:
if($uname != $sql['username']){ 
I changed this to:

PHP Code:
if(strtolower($uname)!=strtolower($sql['username'])){ 
and it works fine!


Thanks for the advice,
AxEh!
AxE is offline
Reply With Quote
View Public Profile
 
Old 08-15-2005, 05:17 AM
asm
Extreme Talker

Posts: 217
Location: UK.Lancashire(true)
Trades: 0
lol as long as you are sorted
asm is offline
Reply With Quote
View Public Profile Visit asm's homepage!
 
Old 08-16-2005, 10:13 PM
AxE
AxE's Avatar
Skilled Talker

Posts: 62
Trades: 0
Okay, as I dont feel the need to grace this disguisting forum with another beautiful topic created by me, Ill just ask my question here as its related :P (kidding about the disguisting, this place rocks )

Okay, so yeah, now im up to coding my forums for my game, Ive got categories and forums and topic listings etc. etc. etc. all done, but is there any way to make an SQL query select sticky topics first (WHERE `state` = 'S'), but then select the rest of them ordered by the `id` column? I can order "`state` DESC, `id` DESC" which returns sticky topics first, but then all the Normal topics spring to the front and the locked topics get shoved to the back.

I can easily do this with multiple queries, or store all them in arrays and reorder, but I want to cut back on my query amount.. im doing around 8 per page load as it is (only on the forums, a stanard logged in page in my game only does around 2 queries.) and I dont want to have to add an extra 200 lines of array messing... im already on 900 lines as it is, its getting pretty crowded.


Thanks,
AxE
AxE is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Nooooooo case insensitive queries -.-
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.24535 seconds with 12 queries