-1

I'm trying to connect too two databases, the reason for this is because I am creating a redeem code system. Once somebody has brought something from me with paypal. They get a redeem code (I give them), then once they type the redeem code

1) It updates MySQL Changing (The Table Redeem)

CODE | PRIZE | EXPIRED | USED_BY |

To

CODE | PRIZE | 0 | $_SESSION['username']

If Expired = 0 code is no longer active if It equals 1 it is active. If they successfully redeem the code It updates EXPIRED = 1 and cannot be used. It also updated User table and set credits+PRIZE.

Anybody know how to do it?

With PHP,

Thanks, Hope you can help!

Sean
  • 12,443
  • 3
  • 29
  • 47
  • 1
    You connect to databases, not tables. While this *could* be solved by simple conditional logic (*and transactions*), it might be better to rethink the "credits+prize" column design. – user2864740 Mar 10 '14 at 17:50
  • 2
    You need to show what you have done so far and specifically explain the problems you are having. SO is not a free coding service. – Mike Brant Mar 10 '14 at 17:52
  • 1
    this is a poor database design. If other parts of this is not in production. This programming should stop until further research and better database design is put together. – amaster Mar 10 '14 at 17:57
  • To connect multiple databases:http://stackoverflow.com/questions/274892/how-do-you-connect-to-multiple-mysql-databases-on-a-single-webpage but as the guys suggested, it's not a good database design. – Sobiaholic Mar 10 '14 at 18:06

2 Answers2

0

try to do you connection like this

 $link=mysql_connect("server", "username", "password");
 mysql_select_db("db_name"); 

then do your queries and then close the connection with the code

 mysql_close($link);

and do the same for the other database

moh kaw
  • 43
  • 5
0

Here's is a solution. update the Redeem table with following SQL: update Redeem set EXPIRED=0 , USED_BY=$_SESSION['username'] where EXPIRED=1 limit 1;

this SQL updates only one available record from EXPIRED=1 to EXPIRED=0,and gives it to the user. after this,you can use: select * from Redeem where USED_BY=$_SESSION['username']

to find the record that belongs to this user,and then you know how to update the user credit.

if the first update failed,the user data will not be updated.

However, the column EXPIRED should be renamed as "INACTIVE",and you should learn how to use transactions and PHP exceptions. Google them.

xsir317
  • 86
  • 2