SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot MediaOhgr's Avatar
    Join Date
    Jul 2001
    Location
    Calgary, Alberta, Canada
    Posts
    189
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    INSERT INTO - specific row?

    I need some help with a PHP/MySQL query I'm trying to perfom. I got a hockey pool all worked into a database and have created codes for each player as the ID (primary key) for the player's row. The row includes the player's goals and assists.

    I've got an HTML form that asks the pool admin for the player's code, goals and assists. My roadblock is I cannot get the proper SQL statement to append the points to the player's current points.

    I've got this:

    PHP Code:
    $query "INSERT INTO players WHERE ID = $player_code
    (goals, assists) VALUES (
    $goals$assists)"
    The Error:

    PHP Code:
    Database query was unsuccessful.You have an error
    in your SQL syntax near 
    'WHERE ID = 12jigin
    (goals, assists) VALUES (1, 1)' 
    at line 1 
    What am I doing wrong?

    It takes the proper player code as well as the proper goal and assist values but still the error?


    Also, does anyone know of a good resource that is for MySQL commands in PHP? Something that would help me find the sort of answer I need here? I've had no luck with the PHP and MySQL manuals at this point.

    Thanks in advance,
    MediaOhgr - But then again, maybe it's just me ...

  2. #2
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    INSERT - Add a new row to the database
    UPDATE - Append or alter a previous entry
    i believe you want to do something like this
    PHP Code:
    UPDATE players SET goals '$goals'assists '$assists' WHERE ID '$player_code' 
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  3. #3
    SitePoint Zealot MediaOhgr's Avatar
    Join Date
    Jul 2001
    Location
    Calgary, Alberta, Canada
    Posts
    189
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Nope

    UPDATE replaces the data completely.

    BUT! I am on the right path now!

    More scouring needed ...

    The MySQL manual is impossible I tells ya!
    MediaOhgr - But then again, maybe it's just me ...

  4. #4
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When you form an UDATE query you specify which columns are to be updated, and only those columns have their values set to the new values specified in the query.

    eg,

    CREATE TABLE FooBar,
    foo INT,
    bar CHAR(1),
    zoot CHAR(1);

    INSERT INTO FooBar VALUES
    (1, 'a', 'a');

    UPDATE FooBar
    SET zoot = 'b'
    WHERE foo = 1;

    SELECT * FROM FooBar;

    will yield one row: {1, a, b}

    The MySQL manual is not a good reference for learning SQL. Check out some of the links in the thread pointed to in my signature.

    Good luck

  5. #5
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Nope

    Originally posted by MediaOhgr
    UPDATE replaces the data completely.

    BUT! I am on the right path now!

    More scouring needed ...

    The MySQL manual is impossible I tells ya!
    UPDATE only overwrites the values set in the query itself. It doesn't affect a column that isn't in the query.
    Refer to sid's example, shows what it does nicely.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*


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
  •