PHP SQL database

Discussion in 'PHP' started by johneva, Mar 4, 2011.

  1. #1
    Hi

    When I am inserting data to sql database which is from a PHP web form, is there an easy way to make the values so they are added to the current value?

    Or would it require me to make a query to find current vales then use PHP to add them before inserting into database?

    Like if the record has a default value of 0 and when I insert the values I want it to go up 1.

    Also what about if I am inserting a value via a variable and wanting to do the same, example record currently has 33 in the database and I want to insert $rating, when the variable is = to 4.

    Cheers
    John
     
    johneva, Mar 4, 2011 IP
  2. srisen2

    srisen2 Peon

    Messages:
    359
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    i think you just want the column to auto increment for you in which case you would not insert a value in the insert statement,

    if you are not talking about auto increment then you just need to process a add via a variable
     
    srisen2, Mar 4, 2011 IP
  3. eleetgeek

    eleetgeek Peon

    Messages:
    129
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Auto Increment. Here is a code snippet in case you need this:

    ALTER TABLE autoData AUTO_INCREMENT=100
     
    eleetgeek, Mar 4, 2011 IP
  4. ACME Squares

    ACME Squares Peon

    Messages:
    98
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    UPDATE table_name SET value = value + ? WHERE id = ?
    Execute using $rating and $id

    This is exactly the sort of thing databases excel at. Any data manipulation that can be done in PHP, can be done directly in SQL.
     
    ACME Squares, Mar 4, 2011 IP