0

I have this

$sql=mysql_query("SELECT EMAIL FROM USERNAME WHERE EMAIL <> '".$_REQUEST['EMAIL']."' AND EMAIL NOT IN (".$str.")") or die("Error: ". mysql_error(). " with query ". $sql);

for example $str holds the value 'd','f' and there is a d and f in the EMAIL column in my table.

When I run the query I get this error "Error: Unknown column 'd' in 'where clause' with query"

I am a complete noob to mysql so I hope I'm just missing something very basic here. Any help is greatly appreciated!

2 Answers 2

2

Nice SQL injection hole there. Enjoy having your server pwn3d.

The IN syntax works either as

WHERE field IN (value1, value2, value3, ...)

or

WHERE value IN (field1, field2, field3, ...)

Given you're getting the 'no such d, you're probably forgetting to quote those values, producing

WHERE field IN (d, f)

which is interpeted as "field d" and "field f", where it shoul be:

WHERE field IN ('d', 'f')

Note the quotes - they turn those d and f's into strings, not field names.

Sign up to request clarification or add additional context in comments.

2 Comments

thats what I'm not understanding, I'm sure the variable in between the () is set to 'd','f'
and thanks I actually just learned about using mysql_real_escape_string yesterday haven't had a chance to go through all of my files yet, thanks for the heads up
0

you're missing single quotes after the NOT IN part. It should be:

$sql = mysql_query("
        SELECT EMAIL FROM USERNAME WHERE EMAIL <> '".$_REQUEST['EMAIL']
        ."' AND EMAIL NOT IN ('".$str."')"
    ) or die("Error: ". mysql_error(). " with query ". $sql);

Also, as Marc pointed out, you're better using mysql_real_escape_string() on client variables you're going to put inside your queries.

2 Comments

when I just tried this it now says "Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'd','f'')' at line 1 with query "
oh, my bad, I didn't think about the possibility that $str had single-quoted text in itself

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.