Forum Moderators: open

Message Too Old, No Replies

Javascript saving to MySQL database

         

Gero_Master

6:11 am on Jan 9, 2006 (gmt 0)

10+ Year Member



Hello!

This time I am already building a visitor counter which I could share with my users. I tried to google for any tutorial of JavaScript saving variables in database. Or a PHP file co-operating with JavaScript.

Idea is a simple visitor counter. Every time the script is called (page view) it performs this: Existing count + 1. Then it saves it to the database where id is same as the id given in the address of the script. After all that is done, it would display the count in numbers at the page the script was called from.

I think I would need to mix JavaScript and PHP, but I'm truly hopeles in JavaScript ;)

DrDoc

7:56 am on Jan 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Why don't you just use PHP to increase the counter?
JavaScript itself cannot be used for server side functionality like this. You would have to resort to some form of loading of a page/image/other which in turn triggers updating the db.

Gero_Master

11:29 am on Jan 9, 2006 (gmt 0)

10+ Year Member



Idea is to be able to add this counter to a page which might not have possibility to use databases or PHP. Im making it to be a hosted-counter. I tried to include plain php file with javascript, but it didnt work

DrDoc

6:11 pm on Jan 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You still need something that can write stuff to the server ... which means some form of server side language.

Or, you could always run a server side Java applet, which then writes to disk.

Bottom line -- you cannot do this with JavaScript alone. You will need a server side language to handle writing to a file/database/whatever.

If this is a remotely hosted script, then I guess you need it on your end (which means everyone writes stuff to your server).

Gero_Master

7:16 am on Jan 11, 2006 (gmt 0)

10+ Year Member



OK. Thanks for your reply,

I think I have came up with an idea which would shift the variable stored in database for javascript to use. I thought of adding a hidden textbox, which will have the value of the value found in the database. Javascript would then read the value of that field and print it on the screen.