jello32
asked on
select syntax
In side a php block I have the following:
$sql2 ="SELECT accountID, account_desc FROM $table_name2 WHERE $type1=accountID";
I can run this query from mySQL and it runs fine however I'm getting a sql syntax error inside the php block. I've tried it with single quotes around the second accountID and same error.
What am I doing wrong?
$sql2 ="SELECT accountID, account_desc FROM $table_name2 WHERE $type1=accountID";
I can run this query from mySQL and it runs fine however I'm getting a sql syntax error inside the php block. I've tried it with single quotes around the second accountID and same error.
What am I doing wrong?
What is the syntax error you are getting?
ASKER
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '='accountID'' at line 1
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I just realized my error. I had type as varchar instead of smallint.
That doesn't make a sense, because you can use integers with varchars but not vice versa.
In SQL syntax, you don't need quotes around integers, but need them around strings.
Still doesn't make sense, because error you got is like your column name is missing from the query.
In SQL syntax, you don't need quotes around integers, but need them around strings.
Still doesn't make sense, because error you got is like your column name is missing from the query.
ASKER
Once I changed it to smallint, it worked.