-6

i want to transfer data from column to another table column using PHP for example table1 has a column "amount" and table 2 column "total". how can i transfer/copy the value in "amount" to "total"?

sory for my bad english

edit: i use MySql db

Barmar
  • 741,623
  • 53
  • 500
  • 612
ronell
  • 11
  • 2

3 Answers3

0

You can simple use below query if you are looking to update MySQL table from PHP.

UPDATE `table` SET amount=total;
TIGER
  • 2,864
  • 5
  • 35
  • 45
0
$update = mysqli_query('your_connection', 'UPDATE $tablename SET column1 = '$value1', column2 = '$value2' WHERE Condition');

For details: http://dev.mysql.com/doc/refman/5.7/en/update.html

VishalParkash
  • 490
  • 3
  • 15
-1

Use this. here I use userId to select a particular row. you can alter it or not use it according to your requirement.

$query = "SELECT amount  FROM table1 WHERE userId='{$id}'";
$result = mysqli_query($con,$query);

$sql = "UPDATE table2 SET total='{$result}' WHERE userId='{$id}'";
mysqli_query($con,$sql);
ab29007
  • 7,611
  • 2
  • 17
  • 43