Jump to content

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

Edited by topcat
Link to comment
https://forums.phpfreaks.com/topic/276507-how-to-add-values/#findComment-1422813
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.

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

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.