creating a database in javascript using xampp - javascript

I am wanting to use a database in javascript. I am familiar only with xampp for databases. With the code snippet .openDatabase('test1'.x .x .x) A new DB 'test1' is created if one doesn't exist, otherwise it opens 'test1'. Where is this DB found? And probably more importantly,how do I make use xampp instead? Of course should I actually be using javascript at all?
I do understand that what I am asking is not that secure. At this point in time, I don't care. I need to get some sort of practice before adding in extra levels of difficulty.

For your need, you can see the tutorial from: https://www.airpair.com/javascript/complete-expressjs-nodejs-mongodb-crud-skeleton
other tutorial:
http://teknosains.com/i/simple-crud-nodejs-mysql
For other CRUD with JavaScript Tutorials:
https://google/MkVg6Q

Related

How can I add a JSON object created with angularjs to an array on my server

I'm mainly a front-end devloper, so the basic server-side aspect of the project I'm working on is escaping me.
My main webpage has a list of products pulled from a JSON array with angularjs' ng-repeat, but I'd like to add an administrative page in which authenticated users could push a JSON object to the array. How can I do this with no experience in any server-side scripting languages?
I hate to be the bringer of bad news, but when dealing with user permissions, you need to be using some kind of back-end technology.
Theoretically, you could store authentication information in the JSON that denoted whether or not a user is an admin, and display the content/assign permissions accordingly. The problem with this technique is that, since the code is on the client side, hacking the admin page would be as easy as altering the JavaScript. This method would provide literally no security whatsoever.
If this is okay with you, then go ahead. But I would strongly advise learning some kind of server-side technology.
Given that you're a font-end developer, I'm assuming you already know JavaScript, so maybe doing this in Node would be a good option. Node does have a learning curve in and of itself, but knowing JavaScript will help significantly. You'll also need some kind of basic database to store the login information. Some kind of noSQL dialect such as MongoDB would probably work well here.
For doing advanced permissions, you'd want to use something like LDAP or Active Directory, but for what you're describing this would probably be overkill.
Remember, learning new things is fun! Good luck!

Pass and get variables from server for JavaScript/HTML site

so I need to pass and get variables from a server for my HTML Site (JavaScript). I'm trying to make a online game so I need to pass variables like names and all players online. I'm a total noob with stuff like servers so how can I get a simple server to hold variables and read and write files or something like that, because I want to create folders for accounts on the server.
Thanks in advance! :)
My advice is to learn PHP. It's one of the easier server-sided languages.
You should store your data in databases. For example mysql. You will also have to learn how to do this ;-)
Use AJAX in case you want to get the data from the server while the site is already loaded. Google it ;-)
If you want to create the server yourself on your own computer instead of using one in the internet you should use something like XAMPP. It includes every program you need for the beginning without the configuration-pain ^^
Overall you will have to do a lot of learning ^^ Noobs don't create games, so stop being one ;-)

Creating a note taking app using JQuery mobile and phone gap

I have an app i'm developing with JQ Mobile and PhoneGap. Within this app, i want to include a 'Notes Taking' page and it has to do the following.
Make new notes and save them locally.
Recall them whenever i need to,
Edit them and delete them
i could not find a good example to follow, i tried this:
http://tutorialzine.com/2012/09/simple-note-taking-app-ajax/
but he lost me at the index php and how to implement that, i also tried this example:
http://miamicoder.com/2011/building-a-jquery-mobile-application-part-1/
but its so complex i got lost in all the code.
I'm a beginner at programming and my JavaScript is very very poor and i have no idea where to start and what kind of code is involved in making this part of the app.
Please help. Thank you.
Your first site (http://tutorialzine.com/2012/09/simple-note-taking-app-ajax/) will not work for you as the examples are embedding PHP into the html and that is not acceptable with phonegap apps.
Your second site is making it way more complicated than it needs to be for your limited scope.
Not going to do this for you but I will give you some advice and places to look.
Draw out what you want the user interface to look like and create that html
Create a load and save function in javascript to... well... load and save your notes. Take a look at the below references:
This will show you how to interact with the local database and store and retrieve info. Always a good thing to read the documentation.
This is a great resource for help all sorts of stuff. In this case, with SQL queries.
Test, test, test. With the above, you will be able to figure it out if you put your mind to it. Come back here and post specific questions with code samples of what you have tried if you get stuck.

How can you read and write to a MySQL database starting at a JavaScript web game?

First of all, I'm not much of a programmer if at all. This question may seem silly but I would honestly like some advice from real programmers.
I'd like to make a bit of an adventure game on a webpage.
Could I make it by having a MySQL database setup to store variables while JavaScript, HTML and CSS is used for the user interface and JavaScript for the game programming and PHP to communicate with MySQL.
I don't entirely understand it but I followed a tutorial and got it working. It also showed me how you can replace text on the screen by giving that text an elementid and then just setting its value to other text.
In this tutorial script, it has it so when the JavaScript file wants to communicate with php, it will open the php file with a ?=value at the end of the hyperlink where the value part turns into some kind of MySQL search value.
Something like this:
xmlhttp.onreadystatechange=function()
xmlhttp.open("GET","index.php?q="+str,true);
and then in the PHP file:
$q=$_GET["q"];
$sql="SELECT * FROM user WHERE id = '".$q."'";
This means you will always search by specific id number. The problem with this is that the php file is always set to look at the exact same table.
Sometimes you want to look at different tables, or multiple values from multiple tables, etc. Basically, you should be able to select each value like it's a record from one of those automatic DJs that radio stations used to have. Also, sometimes you'd want to write or append the database like when variables change and need to be updated and all of that has to happen securely.
The only thing I can think of is to have a ton of php files that work the same way and call the appropriate file when you want a certain kind of response. But then if I have a file on my website that has a php file that lets me write TO the database then someone can just read the javascript code, see that, and then basically hijack the mysql database.
So how can I securely do this?
I would recommend you to look into using jQuery and Ruby on Rails.
jQuery is a JavaScript library that will make easy your interaction with a server (MySQL) and will help you to get code that works in a lot of different web browsers.
Ruby on Rails is a web framework that will encapsulate everything you need to store state (game data) to a database (MySQL) and handle secure communication, as well as a host of other needs you may eventually face.
In addition to jQuery and Ruby on Rails, there are tons of other comparable frameworks you could use.
YUI3 (http://yuilibrary.com) and Django are two more examples. Express (for Node.js) is a JavaScript back end framework (like Ruby on Rails) that you could use with your existing JavaScript knowledge.
Anyway, good luck!
Theoretically, without moving towards different frameworks, here are a few things to think about...
I think you have the right idea with this what you are trying to do. The PHP file is used as server side logic. It should not be available to the user.
What the user can see is that there is a function available to make changes to something. This he will see from your AJAX call in JavaScript ( xmlhttp.onreadystatechange=function() xmlhttp.open("GET","index.php?q="+str,true); ).
Your responsibility, in the PHP (server side logic) is to make sure you scan the parameters to this function before you allow any changes to be made on the Database.
As with any requests to a database, you need to make sure you are escaping the parameters before any call is made to prevent SQL Injections.
As with previous answer, there are some libraries that exist that have some tools already built in. Some poeple prefer certain tools/languages/libraries over others, but they can all pretty much all do the same thing. What changes is a bit of how it's done. I think you are on the right path, just need to protect those PHP pages of injections and inputs/parameters you do not want.
If you are using multiple PHP pages for different actions, it is possible to have the same PHP script accessed from all other pages. Therefore your escaping (preventing SQL Injections) can be done in the same script and don't need to include it in every single PHP page that makes a database call.
Hope this helps a bit!

Accounts in serverside JavaScript (node.js)

I'm making an online game and I was wondering - how can users create accounts? Do I need a database, and if yes, which one? Also how do I get information from the users? I believe by using html tag, but how exactly? I'm not using PHP for the serverside, but node.js.
There are so many answers to this question it's tough to begin at one place.
I'll just suggest some technologies because that seems to be what you're looking for. Ultimately I recommend you research this area and make up your own mind on what you'd like to use.
You can use a database to store the user information. NoSQL is popular nowadays so I'll go for a MongoDB solution http://www.mongodb.org/
You don't exactly need to use HTML tags as there are template solutions written for node.js. I recommend jade https://github.com/visionmedia/jade
There are frameworks and middleware created to make all of this easier. Check it out here https://github.com/joyent/node/wiki/modules

Categories

Resources