php - how to Check string present in database column? -


i have document table fields id, sender_id, receiver_id , receiver_id contains string value u12,u13,u14 logged in user , want find records in receiver_id contains user_id means user_id u13. how write query fetch records.

my query is:

$seldoc="select * documents sender_id='u".$_session['userid']."' or  "u".$_session['userid']." in (receiver_id) order id desc"; 

but got error unknown column 'u13' in 'where clause'

you string concatenation messed up, should be: (further simplified)

$seldoc="select * documents 'u".$_session['userid']."' in (senderid,receiver_id) order id desc"; 

when statement above parsed, this:

select *    documents   'uxx' in (senderid,receiver_id)  // xx userid order  id desc 

as sidenote, query vulnerable sql injection if value(s) of variables came outside. please take @ article below learn how prevent it. using preparedstatements can rid of using single quotes around values.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -