Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Is passing PHP to JavaScript best practice when dealing with databases

I was wondering if passing data gotten from a database to JavaScript variables is best practice, maybe for a browser game.

For instance getting a players resources number from the players database and keeping track of that plagers resources, health or something so the number is changed in real time via JavaScript, then pass back to PHP to be placed back into the database on exit to be saved.

1 Answer

Michael Liendo
Michael Liendo
15,326 Points

You're right in your approach. Typically, you'd use your server-side code (PHP) to pull in information from the database, use that information to update the client (browser GET) and once updated, send (POST) that information back to the server so that it can update the DB.

Ah thank you, I just wanted to make sure don't want to start work on something that is not entirely correct.