woocha Posted January 1, 2008 Share Posted January 1, 2008 HAPPY NEW YEAR GUYS !! I am having a hard time understanding why this little script only works when the variable $item_numb is a string of numbers, not when it is letters and numbers. Here is my code, I hope you guys can tell me what I am not seeing or somethins I have done wrong. The information comes from a form that a user would fill out. if ( $action == "update" ) { $merchadmin = $_POST['merchadmin']; $item_numb = $_POST['item_numb']; $merchdir = $_POST['merchdir']; require ("db_connect.php"); $query = "update catalog set "; $query .= " meta_item_title=\"$meta_item_title\", "; $query .= " meta_item_key=\"$meta_item_key\", "; $query .= " meta_item_dec=\"$meta_item_dec\", "; $query .= " file_modified = now()"; $query .= " where merchant=$merchadmin and item_numb=$item_numb"; $result = mysql_query( $query); } echo mysql_error(); the SQL error I am getting is this: Unknown column 'LDUTTS0011' in 'where clause' LDUTTS0011 equals my test item number. Thanks for the help Quote Link to comment https://forums.phpfreaks.com/topic/84005-solved-update-mysql-with-php-errors-out-with-strings-of-numbers-and-letters/ Share on other sites More sharing options...
hitman6003 Posted January 1, 2008 Share Posted January 1, 2008 What data type is item_numb in the database? If it is anything other than int, then you need to have single quotes around your variable: $query .= " where merchant=$merchadmin and item_numb='$item_numb'"; If it is an int, then you shouldn't be letting the user submit alphanumeric values. Quote Link to comment https://forums.phpfreaks.com/topic/84005-solved-update-mysql-with-php-errors-out-with-strings-of-numbers-and-letters/#findComment-427471 Share on other sites More sharing options...
woocha Posted January 1, 2008 Author Share Posted January 1, 2008 The DB field is set to text....Thank you, I did not know I needed to use the single quote. Thanks for the response Quote Link to comment https://forums.phpfreaks.com/topic/84005-solved-update-mysql-with-php-errors-out-with-strings-of-numbers-and-letters/#findComment-427475 Share on other sites More sharing options...
hitman6003 Posted January 1, 2008 Share Posted January 1, 2008 Unless you have a VERY good reason for using text as the data type for an item identifier change it to a VARCHAR that is acceptably long. Using TEXT will kill performance as the table gets larger and use increases. Not to mention if you have an index on that field (and you probably should since you are using it in your where clause and it's a product identifier) the index for a TEXT field will be huge. Quote Link to comment https://forums.phpfreaks.com/topic/84005-solved-update-mysql-with-php-errors-out-with-strings-of-numbers-and-letters/#findComment-427479 Share on other sites More sharing options...
woocha Posted January 2, 2008 Author Share Posted January 2, 2008 Awesome...Thanks a lot... I really appreciate the help...I will change that over today Quote Link to comment https://forums.phpfreaks.com/topic/84005-solved-update-mysql-with-php-errors-out-with-strings-of-numbers-and-letters/#findComment-428190 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.