azw said:
I have had to put single quotes around $inputIdEncrypt in this line:
$Query = "SELECT * FROM $TableName WHERE idEncrypt='$inputIdEncrypt'";
Otherwise I get an error. Can anyone tell me why this is so?
I think your getting to theoretical here. What your query is actually saying is compare the value in the field idEncrypt to the value i specify. Because field idEncrypt is set to varchar and not to (one of the) INT (types) it treats both the fieldvalue and the variable value as strings when comparing... no other reason.
The book your quoting is talking about comparison between a string against a n integer field or comparison using other functions ... WHERE sum(X) > 3 ... and stuff like that.
Its important to keep in mind that not all numbers are automaticaly integers, i mean 'sting', 'string1234' and '1234' can be strings. Just because the last one is made up completely of numbers doesnt make it an integer. It becomes an integer when you specify it as an integer.
In PHP you don't have to declare your variables and variable types but in other languages you somtimes do.
in VB (Visual Basic) for example you do this
Code:
dim SomeString as String
dim SomeInteger as Int
SomeString = '1234'
Someinteger = 1234
The reason for this is that integers are represented by the first 128 (or something like that) numbers in ascii. Knowing if your dealing with an integer value gives you or the application some advantages, when comaring you only have to use 128 chracters instead of the full 256, you need less stroring space and probably more.
One more thing about quotes in strings. Always use the function addslashes on your query before sending it to your database, many a bugin my scripts was caused because i left it out.