View Full Version : updating field in a table
09-03-2011, 09:44 PM
Another question. (I am just getting comfortable with mysql as you can see, but saving all of my examples for future ref). I am trying to add a description for "assorted subs". The field is call "DESC". My code that does not work is
("update table 'subs' (DESC) values (ham,salami,cap) where 'NAME' = 'Assorted' ") Help would be greatly appreciated, Buffmin
09-03-2011, 10:30 PM
1) DESC is a reserved word, don't use it as a column name
2) Don't store multiple, comma separated values in a single column. It violates first normal form of database normalization. read up on this so you understand it.
3) don't enclose a table name in single quotes, doing so you are referring to a string 'subs' and not the table subs. same with the column name.
Lastly, please post error messages when you ask for help. this case the errors are obvious, but in many cases the error messages help with getting you a solution to your problem.
09-03-2011, 10:43 PM
Understand. That helps. Thank you very much.
09-03-2011, 11:17 PM
Your points were well taken. Rather than add a field called DESC, I added a field called DETAILS. Now my table has 4 fields.. NAME, FULL, HALF and DETAILS, and 3 rows... Ham, Turkey and Assorted. Just for grins, I am trying to put a value in the row "Assorted", and in the field "DETAILS'. My code is not working.
('update subs set DETAILS = xxx where NAME = Assorted')
My error is... Unknown column 'Assorted' in 'where clause'
I am using PHP (vers 5). I would appreciate it if someone could help me, and I appreciate everyone's patience.
09-04-2011, 01:39 AM
details = 'XXX'
If you are running it in PHP then wrap the entire UPDATE statement in double quotes.
09-04-2011, 03:44 AM
That worked. Thank you very much.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.