I know that there’s something wrong with my syntax… "select * from tblpayroll where empid = userid"
UserID is a variable…
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The text
"select * from tblpayroll where empid = userid"will be sent through exactly as is to the SQL back end, theuseridpart will not be substituted. So, unless you have auseridcolumn, you’ll probably get an error. Even if you do have auseridcolumn, the results won’t be what you expect.What you need to do depends on whether
useridis a numeric or string value. For numerics, you can use:This will first turn the numeric value into a string and check it as-is.
For string values, use:
This will simply surround the string with quotes to ensure a string comparison works. You need to be aware that this is a bad idea if
useridhas not been sanitised somehow – it may lead to SQL injection attacks. The art of fixing that is outside the scope of this particular question but it’s worth keeping in mind.What to do if your variable is numeric but the database field is a string is another matter. You can do it with
CStrand zero-padding but, since it’s an unlikely scenario, I haven’t documented it here.