Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Aug 2011
    Posts
    192
    Thanks
    112
    Thanked 0 Times in 0 Posts

    updating field in a table

    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
    Code:
    ("update table 'subs' (DESC) values (ham,salami,cap) where 'NAME' = 'Assorted' ")
    Help would be greatly appreciated, Buffmin

  • #2
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,634
    Thanks
    4
    Thanked 148 Times in 139 Posts
    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.

  • Users who have thanked guelphdad for this post:

    Buffmin (09-03-2011)

  • #3
    Regular Coder
    Join Date
    Aug 2011
    Posts
    192
    Thanks
    112
    Thanked 0 Times in 0 Posts
    Understand. That helps. Thank you very much.

  • #4
    Regular Coder
    Join Date
    Aug 2011
    Posts
    192
    Thanks
    112
    Thanked 0 Times in 0 Posts
    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.
    Code:
    ('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.

  • #5
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,634
    Thanks
    4
    Thanked 148 Times in 139 Posts
    Code:
    UPDATE
      subs
    SET
      details = 'XXX'
    WHERE
      name='Assorted'
    If you are running it in PHP then wrap the entire UPDATE statement in double quotes.

  • Users who have thanked guelphdad for this post:

    Buffmin (09-04-2011)

  • #6
    Regular Coder
    Join Date
    Aug 2011
    Posts
    192
    Thanks
    112
    Thanked 0 Times in 0 Posts
    That worked. Thank you very much.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •