Link to home
Start Free TrialLog in
Avatar of jello32
jello32Flag for United States of America

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?
Avatar of gamebits
gamebits
Flag of Canada image

What is the syntax error you are getting?
Avatar of jello32

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
Avatar of slouko
slouko
Flag of Finland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jello32

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.
Avatar of jello32

ASKER

Once I changed it to smallint, it worked.