mysql_query("SELECT * FROM foo WHERE id ='$foo' OR id = '$foo2");
This doesn’t work.
Basically, I want to be able to select it where the id is one variable’s value OR another one’s.
Thanks.
EDIT: The ID column is numerical.
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.
As others have said and you confirmed, the problem is that you are using string literals to compare to a numeric column. To have it work, the query should look like
However, this solution has very very bad code smell!
First off, this is why
INexists: to be able to writeAnd second, are you injecting unescaped strings into your query? If you are, your code is vulnerable to sql injection! Escape and quote your variables to be safe, like this (in the general case):
or alternatively like this, since in this specific scenario you know we ‘re talking about integer values:
Footnote: I am aware that when using
sprintflike this, one could also handle integer values by just using%dinstead if%sas the format specifier. However, I believe that proving you are correctly escaping variables should be possible by just looking at one place (the parameter list) instead of multiple places (did I useintvalon the variable? or maybe I did not, but I ‘m using%din the format string so I ‘m still OK?). It may sound counter-intuitive, but it’s more robust in the face of modifications.