0

Im trying to check to see if value stored in $steamId is already in the table but its not working. What am i doing wrong.

Account_info table

+------------+---------+----------+-----+
| Steam_id   | Partner | Token    | RID |
+------------+---------+----------+-----+
| Steamid222 | Part222 | token222 |   1 |
+------------+---------+----------+-----+

$stmt = $conn->prepare("SELECT Steam_id from Account_info WHERE Steam_id = ':id'");
$stmt->bindParam(":id", '$steamId');
$stmt->execute();    

if($stmt->rowCount() > 0)
{
//user exists
}
else
{
//user doesn't exist
}
candyfreak
  • 13
  • 4
  • 1
    Wrong quotes. `'$steamId'` Should be double quotes `"$steamId"`... or no quotes. Single quotes make it literal. http://stackoverflow.com/questions/3446216/what-is-the-difference-between-single-quoted-and-double-quoted-strings-in-php – chris85 Jun 22 '15 at 23:43
  • 1
    and............ `':id'` remove those too for `Steam_id = ':id'`. you're treating it as a string literal – Funk Forty Niner Jun 22 '15 at 23:47

1 Answers1

1

You are binding the exact string '$steamId' to the id so that it will search for an user with the id of '$steamId'.

$stmt->bindParam(":id", $steamId, PDO::PARAM_STR);

Also you can remove the quotes from the select statement.

$stmt = $conn->prepare("SELECT Steam_id from Account_info WHERE Steam_id = :id");
Burak
  • 5,252
  • 3
  • 22
  • 30