Jump to content

Adding a vaule to an existing value in a sql table


TheStalker

Recommended Posts

Sorry - I dont understand..

 

Do you mean you have a value stored in a table for example

 

Value

20

 

and want to be able to increment this value or make and adition to this value in the table..

 

If so - i think the way I would do it would be to pull the current value and then add the change in PHP then update the field in mysql but you may be able to do this directly with something like

 

Update my_table SET value = value + addition

 

This is not tested though

 

HTH

Link to comment
Share on other sites

A simple example.

 

<form method="post">
  <input type="text" name="row">
  <input type="submit" name="submit" value="add">
</form>
<?php

if (isset($_POST['submit'])) {

  // connect to db.

  $row = mysql_real_escape_string($_POST['row']);
  $sql = "UPDATE tbl SET fld = fld+1 WHERE id = $row";
  if (mysql_query($sql)) {
    if (mysql_affected_rows()) {
      echo "$row updated</br >";
    }
  }
}

?>

Link to comment
Share on other sites

thanks for all the replys ill explain in more detail ( i prob should have from the start)

 

i have a table called accounts that has customerID, Surname, newspaper and AmountOwing

 

when i click a button i want to have the value of a newspaper added to AmountOwing e.g

 

 

if newspaper = "sun" +0.35 AmountOwing

 

else if newspaper ="Times"  +0.45 AmountOwing

 

etc..........

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.