0

I use below php code to generate a random id number

md5(uniqid(rand(), true)

the type of string it generate is something like this

9a423553ce53c4d7a6199fa9254bfdc5

I use that as an ID in Mysql table then I do a standard select query

SELECT * FROM table WHERE id = 9a423553ce53c4d7a6199fa9254bfdc5

I get this error

Unknown column '9a423553ce53c4d7a6199fa9254bfdc5' in 'where clause'

if I just change the id to a simple number like 1 it works.

Why is this?

codenoob
  • 539
  • 1
  • 9
  • 26
  • Have you tried encapsulating that in quotes? In your query `id = 9a423553ce53c4d7a6199fa9254bfdc5` You can compare two columns like `id = other_id` .. MySQL needs to know how to handle your query. – Blake Sep 08 '16 at 23:48
  • 2
    add quotes to the id – odai Sep 08 '16 at 23:49
  • @Blake omg yep it worked.... post as an answer I will accept it. totally didnt not see that. I thought the weird string had some meaning in Mysql. – codenoob Sep 08 '16 at 23:50
  • @codenoob Don't forget to accept the answer if it helped. Thanks. – Blake Sep 09 '16 at 00:04

1 Answers1

3

Have you tried encapsulating that in quotes? In your query id = 9a423553ce53c4d7a6199fa9254bfdc5 You can compare two columns like id = other_id .. MySQL needs to know how to handle your query.

For clarification, should be: SELECT * FROM table WHERE id = '9a423553ce53c4d7a6199fa9254bfdc5';

Blake
  • 2,294
  • 1
  • 16
  • 24