SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to insert data in a row that already has data?

    Could someone please show me how to insert data into a row that already has data. Something like this:

    SETTING
    Code:
    `Column_4` int(3) DEFAULT NULL,
    THIS IS ROW-3
    Code:
    col1 3 - col2 mike - col3 password - col4 is empty
    I need to insert a single character (the number 1) into the empty field under column 4 for user "mike". User name is primary I hope I worded this correctly. I'm using PHP-5.3.8 and MySQL-5.5.18 as localhost for learning.

    Thanks in advance

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,338
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    you want UPDATE, not INSERT

    UPDATE updates a row (and lets you change any of the column values in that row), whereas INSERT inserts a completely brand new row
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I meant to say UPDATE and everything I tried using UPDATE did not work, that's why I'm asking how-to. It's easy if it has data but the field don't have anything in it.

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,338
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Code:
    UPDATE daTable
       SET column_4 = 1
     WHERE column_3 = 'mike'
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    WHERE column_3 = 'mike'
    That's what got me. I was using where column-3 and such.

    Thanks again r937

    I get it now!


Bookmarks

Posting Permissions

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