-1
 $sel1 = mysql_query ("SELECT ID, name, locale, lastlogin, gender,
 FROM  USERS_TABLE
 WHERE (name = ’$user’ OR email = ’$user’) AND pass = ’$pass’");

I tried logging in with the user as (with the user I want being 'test'):

     test')");--

I figured that should eliminate the check for pass but I did not any ideas what I did wrong?

Ivar
  • 6,138
  • 12
  • 49
  • 61
user3388579
  • 43
  • 1
  • 6

2 Answers2

0

You shouldn't use '"'. The " in that string is is not part of the string itself. Try this:

test')--
Ivar
  • 6,138
  • 12
  • 49
  • 61
-1

In your case just use mysql_real_escape_string for checking (documentation).

$user = mysql_real_escape_string($user);
$pass = mysql_real_escape_string($pass);
$sel1 = mysql_query (...

See How can I prevent SQL injection in PHP? however.

Note that mysql_query() is nowadays deprecated.

Community
  • 1
  • 1
jso
  • 484
  • 5
  • 13
  • I'm given that vulnerable sql statement and the goal is to input the injection into the username field the the UI so that I can login with any username. I guess i should have phrased my question better. – user3388579 Nov 08 '15 at 20:20
  • `mysql_real_escape_string` is deprecated. – Ivar Nov 08 '15 at 20:37
  • Sure it is, identically to `mysql_query` which was present in the question (and mentioned in the answer). – jso Nov 08 '15 at 22:20