Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-30-2002, 11:22 PM   PM User | #1
sweenster
Regular Coder

 
Join Date: Sep 2002
Location: Scotland
Posts: 407
Thanks: 0
Thanked 0 Times in 0 Posts
sweenster is an unknown quantity at this point
Help!!!

Any ideas what i'm doing wrong...
I fire this at the mySQL database (from a php script):

SELECT * FROM users WHERE username=sweenster

and i get no response.

i've tried:

SELECT * FROM users WHERE username like 'sweenster'

as well and it still aint workin.

__________________
My body's a temple... and like those ancient Greek ones it's a ruin
sweenster.co.uk
sweenster is offline   Reply With Quote
Old 10-31-2002, 12:38 PM   PM User | #2
kestrel7
New Coder

 
Join Date: Aug 2002
Location: Cape Town, South Africa
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
kestrel7 is an unknown quantity at this point
The sql looks correct to me. The only prob I can see with the first query is that perhaps it should be:

SELECT * FROM users where username='sweenster';

but then again, the latter query:

SELECT * FROM users WHERE username LIKE 'sweenster';

is (as far as I can tell) 100% correct. So perhaps it is a problem with the table or column name. What error does it complain about?
kestrel7 is offline   Reply With Quote
Old 10-31-2002, 01:41 PM   PM User | #3
sweenster
Regular Coder

 
Join Date: Sep 2002
Location: Scotland
Posts: 407
Thanks: 0
Thanked 0 Times in 0 Posts
sweenster is an unknown quantity at this point
well my web host has a built in sql-maintainance program which i also tried using.

I put the first request in and got the response:
"unknown column 'sweenster'"

mind you, the query itself is defined as:

$query = "SELECT * FROM users WHERE username=".$user."";

where $user is referred from the login page
maybe this helps??
__________________
My body's a temple... and like those ancient Greek ones it's a ruin
sweenster.co.uk
sweenster is offline   Reply With Quote
Old 10-31-2002, 04:17 PM   PM User | #4
kestrel7
New Coder

 
Join Date: Aug 2002
Location: Cape Town, South Africa
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
kestrel7 is an unknown quantity at this point
The reason you get the "unknown column 'sweenster'" error is because it is not in single quotes so mysql tries to treat it like a column name but since there is no column name, sweenster in table users it complains.

This should fix your problem:

$query = "SELECT * FROM users WHERE username=\"$user\"";

EXPLANATION:
You have to escape, the quotation marks, otherwise php will treat it as the end of a string which it recognises as a set of charachters enclosed in quotes.

The dot operator acts as a string concatanator and joins two or more strings together.

Fixing these two aspects (as in the code above) should correct the problem.
kestrel7 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 03:03 PM.


Advertisement
Log in to turn off these ads.