MySQL query is mistaking the column name for the value!!! What's wrong?

This is really strange folks. I've never run into anything like this before. Can you help?

MySQL query is mistaking the column name for the value!!! What's wrong?

The value of $apt is 12GH
The column name is 'apt'.
So, why on earth is "mysql_error())" giving me the following error?

Error: Failed at saving data: WHERE apt =12GH
Unknown column '12GH' in 'where clause'

Here's the query
$UPDATE_db="UPDATE `$S_TableName` SET 
`admin_f_name`='$admin_f_name',  `admin_m_name`='$admin_m_name', `admin_l_name`='$admin_l_name'
WHERE apt =`$apt`"; 
		mysql_query($UPDATE_db) or die("L-83<BR/>
		<font color=RED>Error: Failed at saving data: WHERE apt =$apt
 		" . mysql_error());


Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David FavorLinux/LXD/WordPress/Hosting SavantCommented:
My guess is you may have some unprintable character in your code... at first glance...

Pull a copy of your code into vi + type...

:set list

Open in new window

This will show you all unprintable characters.

See if this might be the problem.
Pawan KumarDatabase ExpertCommented:
Your query should be like below-

WHERE apt ='12GH'

Single quotes missing.

Also if you passing a string then it should be in single quotes.
sasnaktivAuthor Commented:
Thanks for the help guys,
First for David: I don't know how or where I should implement ":set list"
Second for Pawan: I've tried it with and without quotes single and double
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

Pawan KumarDatabase ExpertCommented:
Can you provide me the final SQL you are running that is giving error.

It should be like below -

Update TableName
Set col = 'Value'
Where someCol = 'Condition'

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
Maybe Pawan has the right idea here.

Try changing all the backtick characters to single quotes.

Maybe this is some problem in your runtime environment.

You can also skip surrounding column names with backticks or single quotes, to simplify your query.
sasnaktivAuthor Commented:
That did it guys. I removed all the backticks and replaced them with NOTHING!
Problem solved. Although I don't know why it only failed in the WHERE statement.
I left the single quotes around all the variables.
Pawan KumarDatabase ExpertCommented:
Glad that it worked. Single were required.
sasnaktivAuthor Commented:
Thank you guys. I hope I was fair with the point allotment.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.