Web Analytics Made Easy -
StatCounter updating field in a table - CodingForum

Announcement

Collapse
No announcement yet.

updating field in a table

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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
    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.

    Comment


    • #3
      Understand. That helps. Thank you very much.

      Comment


      • #4
        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.

        Comment


        • #5
          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.

          Comment


          • #6
            That worked. Thank you very much.

            Comment

            Working...
            X
            😀
            🥰
            🤢
            😎
            😡
            👍
            👎