SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2005
    Location
    fulham
    Posts
    137
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    javasdcript & MySQL

    is it possible to send information to a MySQL database using javascript?
    Cheers

    Coup

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Yes. You use an Ajax call from the Javascript to whatever server side language you have avaliable which then does the database call.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    Caveat surfer Buddy Bradley's Avatar
    Join Date
    May 2003
    Location
    Cambridge, UK
    Posts
    2,366
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Obviously you should not expose any sensitive information, such as your database name and connection details, in your JavaScript.

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    There is no point in putting any of the database details in the JavaScript since it needs the called server side script to do the database access and since the connection details don't change they are better off being hard coded there rather than being passed in every request. Passing them would just make the requests a lot bigger than they need to be (plus of course having the connection details in the javaScript means that the first person who decides to can totally destroy your database or update it to contain whatever they want it to contain and then change the password to lock you out of it).
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    SitePoint Zealot
    Join Date
    Jan 2005
    Location
    fulham
    Posts
    137
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    [QUOTE=felgall;3389688]There is no point in putting any of the database details in the JavaScript since it needs the called server side script to do the database access and since the connection details don't change they are better off being hard coded there rather than being passed in every request. [QUOTE]

    This sounds like the perfect solution, what kind of server side script could it run could it run a php script, and if it could would it open the script in a new window?

    How complicated would the JavaScript need to be?

    Sorry one major thing I forgot to state is, I want the JavaScript to sit on my clients’ website/server and then send variables using JavaScript to our server/MySQL database so we can process the information accordingly.
    Last edited by coup; May 15, 2007 at 00:27.
    Cheers

    Coup

  6. #6
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    If they are different servers then you have one extra step.

    1. The JavaScript running in your client's visitor's browser does an Ajax call to your client's server to run a server side script.
    2. That server side script passes the request to your server to run a server side script there.
    3. Your server side script updates the database and sends back a response.

    I have a series of introductory Ajax tutorials at http://javascript.about.com/od/learnajax/Learn_AJAX.htm
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •