473,473 Members | 2,169 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

MySql Error 'Unknown Column' from PHP variable

I'm getting an error message that makes no sense to me. I have a table with a
field named 'testkey' for a list of "keys" in the form of ABC10102. I have a
php variable holding a specific key number.

The relevant code is -
$_testkey = 'LAL10102';
$sql = "SELECT * FROM `pro_keys` WHERE `keynum`=`$_testkey`";
$result=mysql_query($sql,$db_conn);

echoing the $sql gives -
SELECT * FROM `pro_keys` WHERE `keynum`=`LAL10102`

But I get the following error -

MySQL error #1054 - Unknown column 'LAL10102' in 'where clause'

?????????

Thanks for any ideas,
Larry L
Dec 8 '06 #1
5 2513
..oO(Larry in Honolulu)
>I'm getting an error message that makes no sense to me. I have a table with a
field named 'testkey' for a list of "keys" in the form of ABC10102. I have a
php variable holding a specific key number.

The relevant code is -
$_testkey = 'LAL10102';
$sql = "SELECT * FROM `pro_keys` WHERE `keynum`=`$_testkey`";
$result=mysql_query($sql,$db_conn);
Strings in an SQL query have to be quoted (and drop the backticks):

$sql = "SELECT * FROM pro_keys WHERE keynum = '$_testkey'";

Micha
Dec 8 '06 #2
Michael Fesser wrote :
.oO(Larry in Honolulu)
>I'm getting an error message that makes no sense to me. I have a table with a
field named 'testkey' for a list of "keys" in the form of ABC10102. I have a
php variable holding a specific key number.

The relevant code is -
$_testkey = 'LAL10102';
$sql = "SELECT * FROM `pro_keys` WHERE `keynum`=`$_testkey`";
$result=mysql_query($sql,$db_conn);

Strings in an SQL query have to be quoted (and drop the backticks):

$sql = "SELECT * FROM pro_keys WHERE keynum = '$_testkey'";

Micha
You have to remind that `` are used to define MySQL fields, databases, or
tables, not values ;)

--
Naixn
http://fma-fr.net
Dec 9 '06 #3
In article <fk********************************@4ax.com>, Michael Fesser <ne*****@gmx.dewrote:
>..oO(Larry in Honolulu)
>>I'm getting an error message that makes no sense to me. I have a table with a
field named 'testkey' for a list of "keys" in the form of ABC10102. I have a
php variable holding a specific key number.

The relevant code is -
$_testkey = 'LAL10102';
$sql = "SELECT * FROM `pro_keys` WHERE `keynum`=`$_testkey`";
$result=mysql_query($sql,$db_conn);

Strings in an SQL query have to be quoted (and drop the backticks):

$sql = "SELECT * FROM pro_keys WHERE keynum = '$_testkey'";

Micha
Thanks Michael,

I've been away from MySql for a while and forgot that. Oddly I have another
query on the same page (different fields and different variable) that uses the
same syntax, though with no backtics and no quotes of any kind that works just
fine.

Larry L
Dec 9 '06 #4
In article <45***********************@nan-newsreader-06.noos.net>, naixn <na***@won-fma.comwrote:
>
You have to remind that `` are used to define MySQL fields, databases, or
tables, not values ;)
I actually never knew that. I just have seen them used in many places, and
never had seen any documentation describing where they were appropriate.

Thanks much for my education.

Larry L
Dec 9 '06 #5
..oO(naixn)
>You have to remind that `` are used to define MySQL fields, databases, or
tables, not values ;)
You don't have to use them.

Micha
Dec 10 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Cathy Hui | last post by:
Do u know why do i get the following message when trying to build the MySql-Python (1.2.0) on my Solaris 8 system? (with mysql 4.0.21 and python 2.4). thanks! error mesg: ld: fatal:...
0
by: Lenz Grimmer | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, MySQL 4.0.14, a new version of the popular Open Source/Free Software Database, has been released. It is now available in source and binary...
0
by: Robert Mazur | last post by:
Solaris 9 - sparc 64bit MySQL 5.0 alpha (installed using binary from MySQL) --------------------------------- Has anyone expereinced this? The client will launch locally and process SQL...
4
by: Adam Smith | last post by:
I have a dedicated server running 'FreeBSD 4.9 STABLE' at a hosting site. They have done some default installations, presumably from the CVS ports package ??. Herein lies the problem, "I do not...
0
by: Gary | last post by:
configure goes goes fine but make produces loads of problems I installed GNU versions of make, tar and libiconv and all installed fine. I hope someone know what this means ? <unknown> ...
1
by: smsabu2002 | last post by:
Hi, I am facing the build problem while installing the DBD-MySql perl module (ver 2.9008) using both GCC and CC compilers in HP-UX machine. For the Build using GCC, the compiler error is...
0
by: cwho.work | last post by:
Hi! We are using apache ibatis with our MySQL 5.0 database (using innodb tables), in our web application running on Tomcat 5. Recently we started getting a number of errors relating to...
1
by: vincedav31 | last post by:
I have a connection to a server and my database. I use it like this in my code : Class.forName("com.mysql.jdbc.Driver"); String DBurl = "jdbc:mysql://138.63.222.7:3306/ns3"; m_connection =...
1
ssnaik84
by: ssnaik84 | last post by:
Hi Guys, Last year I got a chance to work with R&D team, which was working on DB scripts conversion.. Though there is migration tool available, it converts only tables and constraints.. Rest of...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.