How to update a different table with data from another table in PDO

Asked

Viewed 137 times

0

I have a pay-as-you-go table, and in it I have an indemnification code for every transaction, when receiving the update data, I want to take the data and enter in update in another table of the database where 1 of the fields does not have in the other table or

in the table that I will update, has user and value, but n has the code, and to define if really and that user q will receive the code and not duplicately, I need to be specific of that code... anyone could help me? example :

USUARIO 1 bought 30 reais, purchase code xx3

when the purchase is approved, will receive the purchase code xx3 the return of purchase and release of these 30 real credit, and will insert in the table ( the 30 real) credit.

1 answer

1


That seems simple.

1) There are 2 tables. One has user, value. In the other there is user, value and code.

2) Insert the 'code' column into the first table, so the two are equal, you can easily insert this column by a simple SQL command or by phpmyadmin.

3) Now, just take the value of one table, through PHP and insert in the other. You should do this with PHP (variables) and a simple SQL command (update).

4) Use PDO to connect and manage your databases with PHP.

NOTE: show your code attempts so we can help better.

Up until.

  • in case both have the user column, and credits, this would not be enough and my system n allows to create a duplicate user ?

  • 1

    Before adding the value with the SQL command to the other table, you must use an if ($usuario1 == $usuario2) {code.. } to verify that the two are equal. You can transfer only the value for the code, to the table that does not have.

  • 1

    and a good chance to do tmb. I will test this Stefano Thanks! Jaja return to the one hello

Browser other questions tagged

You are not signed in. Login or sign up in order to post.