Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Add to Current Value in MySQL DB

Tags:

php

mysql

Hi i have a DB Entry that only consists of a number. and i want to Make it where users on my site can Exchange from One to the Other and i know how to do all that but i dont wanna Replace the current value i just wanna add for example 1,000 to it what code can i use in PHP ?

like image 363
Robert M Nelson Avatar asked Jan 08 '11 07:01

Robert M Nelson


People also ask

How do I add values to a specific column in MySQL?

First, you must specify the name of the table. After that, in parenthesis, you must specify the column name of the table, and columns must be separated by a comma. The values that you want to insert must be inside the parenthesis, and it must be followed by the VALUES clause.

How can I append a string to an existing field in MySQL?

To prepend a string to a column value in MySQL, we can use the function CONCAT. The CONCAT function can be used with UPDATE statement.


1 Answers

<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_db", $con);

mysql_query("UPDATE `some_table` SET `value` = `value` + 1000 WHERE `id` = 1");

mysql_close($con);
?> 

update like this

like image 56
Mohammad Efazati Avatar answered Sep 22 '22 15:09

Mohammad Efazati