Jump to content

How to add Values


Icewolf

Recommended Posts

Hi

I want to say thank you all for your help. I have one more question. How do I add a field from a form to a field in mysql database. What I want is if the field on the form has 200 and the field in the database has 200 then the field updates to 400 when I hit the submit button. What I am not sure of do I need to query the database first and then add them together?

 

Here is what I have for now.

$query = "UPDATE Points_Rewards Set Bank = '$bank', Reward_1 = ('$reward1' + Reward_1), Reward_2 = ('$reward2' + Reward_2), Reward_3 = ('$reward3' + Reward_3) WHERE Member_ID = '$memid'";
$result = mysql_query($query) or die(mysql_error());

 

Link to comment
https://forums.phpfreaks.com/topic/276507-how-to-add-values/
Share on other sites

Thank you for your response I understand what you are saying. Maybe I didn't say what I need to correct way. Right now when the person goes to this webpage I have for text boxes where the user can put in any number in. From that I want to take the value from the webpage and add it to the value that is already in the database. I was just saying the 200 as an example.

Link to comment
https://forums.phpfreaks.com/topic/276507-how-to-add-values/#findComment-1422806
Share on other sites

The above response is still the way to go just replace the 200 with the value from the form field:

$value = $_POST['the_id_of_the_formfield']; or however you retrieve the value from the form. I would do some checking here to make sure that the value really is an integer to avoid sql injection attacks. such as:

 

if(!is_int($value)){ show a messsage to user saying it must be an integer and exit" }
 

otherwise add it to the existing database field

$sql = "UPDATE `table` SET `column`=`column`+ $value WHERE `id`=1"; (obviously you would have to dynamically set the id.

hope that helps

Link to comment
https://forums.phpfreaks.com/topic/276507-how-to-add-values/#findComment-1422813
Share on other sites

  On 4/4/2013 at 4:05 AM, Icewolf said:

Thank you for your response I understand what you are saying. Maybe I didn't say what I need to correct way. Right now when the person goes to this webpage I have for text boxes where the user can put in any number in. From that I want to take the value from the webpage and add it to the value that is already in the database. I was just saying the 200 as an example.

Did you try using a little logic to look at what I posted and what you posted, and figure out how to USE what I posted?
Link to comment
https://forums.phpfreaks.com/topic/276507-how-to-add-values/#findComment-1422862
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.