1

I am a college student slightly new to web programming and lately I have "ran into a wall" so to speak.

It is hard to explain my problem, since I do not understand everything that is going on, but a friend referred me to this website and I hope that the guidance here will set me in the right direction.

This is what I am trying to do: Create an inventory that can be accessed via a webpage through multiple computers, and can be edited by every user.

What I have already done: I have created the HTML page and added Javascript. The Javascript interacts with quantities of items in inventory, and the user can change the amount of a certain item as they withdraw an item or add an item. But, when the page reloads, the numbers return to their default value of zero.

I have researched into editing cookies through Javascript, but that only works for a single computer. Same problem with "window.name". I have looked slightly into databases, then shuddered and closed the door quickly. If a database is the only option, then can someone please point me toward a beginner's tutorial of databases?

From my viewpoint, the main problem I have is modifying a variable in Javascript on a webpage, then somehow saving that variable to a document in ONE location. This way every computer connected to that network can access the variables and modify them as needed.

I would appreciate any help on this matter!

  • possible duplicate of [how to get the value of client side variable in server side](http://stackoverflow.com/questions/5417001/), [javascript variable into php](http://stackoverflow.com/questions/1515590/), [Access a JavaScript variable from PHP](http://stackoverflow.com/questions/2338942/), [Pass javascript variable to Codebehind](http://stackoverflow.com/questions/8639278/), [How to access JS variable in C#](http://stackoverflow.com/questions/1465732/) – outis Jan 09 '12 at 19:38
  • ... [value of ASP.NET variables for different users](http://stackoverflow.com/questions/8033452/), [php share variable among different users/sessions](http://stackoverflow.com/questions/3475377/) – outis Jan 09 '12 at 19:51
  • Note there are many methods of sharing data between page requests among different users, but since each client communicates only with the server, it must be done server side, so the exact methods available depend on what the server runs, which is [unspecified](http://catb.org/~esr/faqs/smart-questions.html#beprecise). Please edit this information your question. Also, [sample code](http://sscce.org/) usually helps. See also [Writing the perfect question](http://tinyurl.com/so-hints). – outis Jan 09 '12 at 19:55
  • @JacobABridges I whipped up a sample program that reads, modifies, and writes a text file on the server using PHP and Javascript, but it's a tad lengthly, so I probably shouldn't post it here. If you would like me to send it to you, just email me: jsweeney.dev@gmail.com – Jeffrey Sweeney Jan 09 '12 at 20:11
  • @JeffreySweeney: that's not how SO is supposed to work. SO is supposed to be self-contained, so that Q&As can help more than one person. At the same time, code should be just enough to illustrate the answer; it doesn't need to be an entire production system. – outis Jan 09 '12 at 23:56
  • @Jacob: Before you get to implementation, you need to design how you're going to store data. Design questions are better suited for [programmers.SE](http://programmers.stackexchange.com/). SO is for implementation questions, when you've got a specific problem with specific code that isn't working the way you want or expect. – outis Jan 09 '12 at 23:57
  • @outis I understand, and agree. I programmed the sample for my own benefit (I've never tried it before), but I thought Jacob might be able to use it as well. I would have contacted him privately, but he doesn't have any contact info on his profile. – Jeffrey Sweeney Jan 10 '12 at 00:12

5 Answers5

4

Sorry to tell you this, but to have a centralized storage like you intend to have, you need a server. JavaScript was/still is client side so having it work for multiple people at the same time will be impossible.

For this to work you need a server. A local storage wont work because then not all people will have the same data.

mishmash
  • 4,422
  • 3
  • 34
  • 56
  • Currently I am using [Abyss Web Server](http://www.aprelium.com/) for the server. But as far as server side scripting goes, I have zilch experience. Any good ideas for where to begin? – Jacob A. Bridges Jan 09 '12 at 19:45
  • Look up AJAX for the client side and for the server side PHP will suffice. AWS even supports it: http://www.aprelium.com/abyssws/php.html – mishmash Jan 09 '12 at 21:17
4

From my viewpoint, the main problem I have is modifying a variable in Javascript on a webpage, then somehow saving that variable to a document in ONE location. This way every computer connected to that network can access the variables and modify them as needed.

That, my friend, is a database. Yes, a database is the solution. What you need to understand first about web development is that there are two kinds: client side and server side. Javascript is client side development, meaning it works on the user's browser. You have a variable on the client side, but only that client can see it. Server side is different. It exists on the server alone. Your server "serves" your page (and any content from a database or whatever) to the client. Therefore any changes on the server will be visible to all the clients (what you want). To program server side, you have to use another language other than javascript (you can use node.js but that's entirely different than client side javascript). Other languages include PHP, Java, C#, etc.

Therefore, you need to look up server side scripting.

Joseph Marikle
  • 76,418
  • 17
  • 112
  • 129
  • *sigh* Oh well. A database it is. Thank you for your answer! I did forget to mention that I am using [Abyss Web Server](http://www.aprelium.com/) as the broadcasting server for the inventory page. But when it comes to server side scripting I know close to nothing. Do you have any recommendations on where to begin? And from what I have seen, databases have issues when being edited by more than one user. – Jacob A. Bridges Jan 09 '12 at 19:46
  • @JacobA.Bridges I feel your pain :P but it's definitely worth learning, and necessary for any serious web development. Good luck! Oh! and if you do run into any problems, don't hesitate to ask for help on here :) – Joseph Marikle Jan 09 '12 at 19:48
  • Thank you for your comment, and the encouragement. I edited my comment above, for it was posted prematurely lol. – Jacob A. Bridges Jan 09 '12 at 19:51
  • @JacobA.Bridges You're welcome. :) Unfortunately, I am a complete noob when it comes to client side development (I only just recently started learning it), but PHP would probably be the easiest to start learning with. It's cross-platform, has excellent documentation, and is easy to get set up. You can google for LAMP (for Linux) or WAMP (for Windows) to get a server running on your personal computer. From there, have fun with it and you'll learn it quickly. :) – Joseph Marikle Jan 09 '12 at 19:56
2

You will need a backend language,

such as php, asp, .net, java, etc.

Using this backend language you will be able to make queries to a database, for example a mysql database,

I would recommend you to take a look at php and mysql as they are both free:

http://php.net, http://mysql.com

to get you an environment working quickly to debug NOT for production, try WAMP:

http://www.wampserver.com/en/

Luc Laverdure
  • 1,398
  • 2
  • 19
  • 36
  • Or [XAMPP](http://http://www.apachefriends.org/en/xampp.html). These "pre-built" stacks will get you a webserver capable of hosting PHP (and MySQL and more!) very quickly. Install, run, visit http://localhost/ and start playing. – Tom Redman Jan 09 '12 at 20:35
0

You can avoid having your own database and store inventory data in some cloud storage like Google Spreadsheet. But of course that will also require some learning.

If you have a Google account simplest thing to do is to create a spreadsheet fit for storing your inventory and then generate a web form from that spreadsheet. Finally just embed that generated form in your html and you're good to go. All the changes in inventory will be reflected in the Google doc's spreadsheet.

anubhava
  • 761,203
  • 64
  • 569
  • 643
0

There are multiple parts to implementing a shared inventory app. At the highest level, you can break this down to transferring data between the browsers and the server (client-server communication, which will be based on HTTP and includes technologies such as AJAX) and sharing data between requests. The former has been directly covered many, many times before on SO (see linked questions in the "Linked" section on the right of the page). The latter has also been covered, but perhaps not as directly, so the information is scattered.

The exact design and implementation for both depends on what server-side technologies you have available. An ASP.Net approach will be quiet different from a PHP approach, which will differ from a JSP approach. Each has different way of persisting data in ways that can be accessed by multiple users. Some basic ways are shared memory, files and (as you've already mentioned) databases.

Before shying away from databases, keep in mind that there are many tricky data related tasks that must be performed. If you don't use a database, you'll need to implement these yourself. In the end, you'll wind up implementing a database of some sort, one that likely has fewer features, more bugs, performs worse and will require other developers who may work on the project (an projects can live longer than you expect) to first learn your data storage system.

Community
  • 1
  • 1
outis
  • 75,655
  • 22
  • 151
  • 221