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?
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

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.
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

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
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.