-3

How could varchar field in Mysql table can accept values without single quote in query where clause

MRM_RA1_ID='".$_SESSION['EmployeeID']."' (Not working)
MRM_RA1_ID=".$_SESSION['EmployeeID']."  (Working)

MRM_RA1_ID is varchar field

I am not getting this behaviour. Mysql version is 5.1.

Can someone please explain me.

Shri
  • 703
  • 3
  • 11
  • 28

1 Answers1

-1

Because it is taking value of $_SESSION['EmployeeID'] Just take its value as variable value. And if you want simple string then single quotes must be used.

VARCHAR_FIELD = $Variable

VARCHAR_FIELD = 'Any data'

Anjum
  • 681
  • 3
  • 14
  • 38
  • session is array and EmployeeID is one of its key. – Anjum Jan 13 '15 at 11:41
  • And in his case, it is taking value of session array where it's key is EmployeeID – Anjum Jan 13 '15 at 11:42
  • in session value will be any 5 digit number – Shri Jan 13 '15 at 11:46
  • no problem with 5 digits or 10 digits (unless there is no restriction on database level likewise) – Anjum Jan 13 '15 at 11:50
  • You have to use single quotes when you are passing string. And you don't have to use single quotes when passing variable value or lets say value of array's key. And you are passing value of session key where key is EmployeeID – Anjum Jan 13 '15 at 11:52