Skip to main content
GameDev.net gamedev.net
🔒 Locked

[web] Transmitting from Javascript -> SQL

Started by djz Aug 26, 2011 at 10:51 PM 1 replies 2.5k views
Original Post
djz
djz
I want to add a feature to my website where people can "draw" on pages. I'm limited by what my host can provide (php/mysql) - otherwise I would write a server app to handle this, but what I need to do is capture strokes, when a person is finished with a stroke, it should upload the stroke data to the SQL DB. I'm not that experienced with php but I imagine I'm going to need to use php to actually throw the data into the DB.

Is this crazy? Is this possible? It seems like it should be fairly trivial, i'm just not sure how everything should be hooked up.
touch_the_sky
touch_the_sky
1) php / mysql + js is exactly (but not necessarily) what you need to create a web app
2) it's a bad idea. think bandwidth & user experience for example
3) instead, have an option for users to save the drawing when they're happy with it (ajax is the keyword you want to google)

Google around for some webdev tuts. This sounds like an app which may require user authentication? I'd suggest looking at some decent php framework -> would save you time + at least some sort of security would be on by default.

Good luck
stormwarestudios
stormwarestudios
already done: http://www.permadi.c...g-php-and-ajax/

some suggestions:

add an 'onmouseup' event handler to canvas, which:
  • places a "busy" spinner over the canvas object (making it inaccessible)
  • converts the canvas object to base64 and transmits to php script
  • (bonus marks) swap the visible canvas out of visibility, copy its contents to a new canvas, and save the hidden canvas through the means linked above, then destroy that canvas on XHR success. This method might be faster, and would lend to a more fluid user experience, since the save time could be long. It would even be possible to chain saves; push each "mouseupped" canvas onto an array, and simply loop through them to save to the PHP script. Dojo Toolkit's XHR functions and Deferreds would be the way to go here.
  • (bonus++ marks) store canvas object revisions in your MySQL table
    as for a PHP toolkit, check out RedBeanPHP ORM. It is the bees' knees and cat's pyjamas.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.