Jump to content

[SOLVED] Unknown column '$variable' in 'where clause'


Recommended Posts

Hi,

 

I'm getting a: Unknown column 'DW' in 'where clause' error, where DW is passed in a query string 'products.php?prodid=DW' and turned into the variable $prodid_query. The actual query is:

 

$result = mysql_query("select * from products_tbl WHERE prod_id = $prodid_query LIMIT 0, 30 ") or die(mysql_error());

 

The table field 'prod_id' is set as varchar. The strange thing is if I alter the data and use '01' as the $prodid_query variable it works fine...

wrap $prodid_query with in quotes:

$result = mysql_query("select * from products_tbl WHERE prod_id = '$prodid_query' LIMIT 0, 30 ") or die(mysql_error());

 

MySQL will treat the value of $prodid_query as a column name and not a string.

wrap $prodid_query with in quotes:

$result = mysql_query("select * from products_tbl WHERE prod_id = '$prodid_query' LIMIT 0, 30 ") or die(mysql_error());

 

MySQL will treat the value of $prodid_query as a column name and not a string.

 

so simple, and of course works.... Thanks for the help!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.