Avatar of jello32
jello32
Flag 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?
PHPMySQL Server

Avatar of undefined
Last Comment
jello32

8/22/2022 - Mon
gamebits

What is the syntax error you are getting?
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
slouko

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
gamebits

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
jello32

ASKER
I just realized my error. I had type as varchar instead of smallint.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
slouko

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

ASKER
Once I changed it to smallint, it worked.