Forum Moderators: coopster

Message Too Old, No Replies

Error in Query

searching through a database

         

Francis

3:44 pm on Jun 22, 2003 (gmt 0)

10+ Year Member



I think this is kinda simple, but I'm so totally lost.

I wanted to perform a search on a database using an input form object with the name d_user. I also created a field in the database named user and placed in the following data- 1101 and abcd. It's declared as VARCHAR(10).

However, when the query was performed using abcd, I got the error:

Error performing query: Unknown column 'abcd' in 'where clause'

But when I used 1101, it went through without a hitch.

I hope my question is clear enough.

Thanks for the help.

jatar_k

3:54 pm on Jun 22, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



it looks like, from that error message, that abcd was listed as the column name and not the value.

They should both work.

select * from tablename where user='abcd'
select * from tablename where user='1101'

did you change anything else in the query when you swapped the value to 1101?

Francis

10:17 am on Jun 23, 2003 (gmt 0)

10+ Year Member



The name of my column for that particular record is id_name.

Here is also the query that I've executed:

$result = mysql_query("SELECT * FROM going_db where id_name=$id_name");

going_db is the name of the table, and I get the value of id_name from a post coming from a form.

Thanks.

jatar_k

4:27 pm on Jun 23, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if your col id_name is varchar then you need to put single quotes around your value like so

mysql_query("SELECT * FROM going_db where id_name='$id_name'");

I would think that is why the 1101 is working int values don't need quotes around them. Interesting that it wouldn't error out selecting an int against a varchar col though.

Francis

4:12 am on Jun 24, 2003 (gmt 0)

10+ Year Member



It worked! Thanks a lot... again, most especially for the patience for people like me.

jatar_k

4:16 am on Jun 24, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



don't worry so much, that's what we are here for. :)