how to develope CRUD by backbone.js by database - javascript

I want to use backbone.js .
http://documentcloud.github.com/backbone/examples/todos/index.html
In this example it store in the local storage.but i want to store in the database so for this what changes i need to do in the code.
Please suggest .

If I understand your question correctly it's something I was wondering about, I recently posted a question about RESTful persistence in PHP.
Since Javascript doesn't have access to the filesystem you can't use it to write to a database. You'll have to pick a backend server in another language like PHP, Rails, Ruby, whatever. There are a few suggestions for PHP at the link above.

Related

Save user input data

I'm trying to find a solution to my problem for quite some time. This is the web app that does some calculations.
https://nicolasbg87.github.io/upwork-style-number/index.html
I'd like to know if it's possible to save user input to an online database so it can be opened and edited. It'd have to autofill all the input fields once called. I was also thinking about the option to save whole page already filled and just store it as it is.
I have to mention that it won't always have the same amount of <tr>s inside each table, and that complicates the whole process for me.
I'm running out of ideas and would be very thankful if anyone could assist me in this matter.
You have 2 options, store the data in the client, this means to store in the localStorage of the browser (this only will let availability of information for the client that store it and not share the data with other users or from the other computer). The other option is as you say store in a database but this will require to you use a backend Technology like PHP, Java, Ruby, Python, etc. And a database engine as MySQL, Postgress, and so on. And the others NoSQL like MongoDB, Redis, etc.
According to I see in the webpage the information is well structured and wouldn't be complicated to store it.
In Html, it is not possible. To store data in a database would require another language. If you used Javascript it would be possible, but it would be really insecure and very difficult. I suggest using PHP and Mysql to do it, for the best outcome. So basically Html is not a database language and requires a backend language.

Inserting and retrieving data from MySQL database from AngularJS site

As a learning project I have been using AngularJS to create a quiz website. I having a web hosting package with 123-reg.co.uk and managed to create a MySQL database with a table I hope to store peoples scores who complete the quiz.
Ultimately this means I will be able to build a scoreboard on my site. I am hoping to create two functions in my site, one which will retrieve the scores and one which will post new scores. I believe in order to achieve this I will need to use PHP to retrieve and post data however I am a little unsure where to start.
If anyone could provide me with some pointers I would be grateful as I am not particularly familiar with MySQL databases or PHP. I did find this guide on connecting to MySQL database from 123reg.co.uk however I am struggling.
Thanks,
Simon
The tutorial that you mentioned is outdated, relies on mysql_connect that was deprecated in PHP 5.5.0 and removed on PHP 7.0.0. Find a more up to date tutorial that uses mysqli or PDO.
Also you will need to learn some security concerns, I really recommend you to study a bit before doing this, since you can have serious problems if implement a insecure script to do this.
There are great PHP Frameworks that implement all of this in a secure and easy way, try searching for Laravel Framework. Isn't for begginers, but with a little knowlegend of PHP Object-oriented and MySQL (or any SQL supported by Laravel) you can do what you want.
There are also a nice site to learn Laravel, called Laracasts with very nice screen-casts teaching Laravel (for begginers or not).

How do I connect a sql server to my Javascript game?

I'm working on a project and I just need a holistic overview on how to go about it.
I'm going to use HTML/CSS canvas to make the game.
However, the game involves visualization of large amounts of data that is best served in a database. What I do not know how to do is:
Link my HTML/CSS game to a SQL database
Parse a text file to populate the database.
I don't have specific issues I just don't even know where to start? Some people have said AJAX? Others have said parse.com?
You have two options:
write a server-side application to serve data from a DB
use client-side HTML5 storage (such as local storage, WebSQL, IndexedDB, etc)
If you use the server implementation you will need AJAX to communicate with the server.
To do this you will have toove beyond JavaScript and learn server side programming. The good news is there are tons of awesome server side languages that make building websites easy.
If you come from a javascript background, ruby would probably be an easy transition. I'd suggest Sinatra.
If you are using SQL server, c# and asp.net are great choices that are very well designed, thou c# is very different from JavaScript as a language.
Like python? Web2py and Django are good.
Then there is PHP and java...
You would probably write an API in one of these server side languages, access it using Ajax to retrieve Jason and process it.
And don't bother with parse.com. write your own parser in the language of your choice. Its usually really easy, and instructive.
I think you already know a language you can use. How about javascript? Of course a real serverside language like Java or PHP would be better - maybe as already told: ruby but why not try it with node.js:
Node.js could be the first thing you may look at. (http://nodejs.org/)
It's really nice & well documented - there is also a big question about node.js with mysql: MySQL with Node.js which also works fine.

Broad Design Implementation: PHP, MySQL, Knockout

Spent the last few weeks learning MySQL and PHP. Then I learned some basic knockout.js and I'm rewriting a lot of things.'
Just wanted to check before I go further if this is the most efficient way of doing things with PHP/MySQL/Knockout.js-
Pages are php with Knockout which is pulling and pushing data via ajax/Json to separate php files which then push to MySQL. The login system is PHP & MySQL. And I'm using $_SESSION variables to limit content (its a project management system) to what each user is allowed to access.
Is this the current way of doing things? Or am I still behind the times
thanks!
-newb
knockout is the way to go, maybe in combination with jquery in the client side you are good to go, but i recommend you to use a php framework for the server side like codeigniter, zend, symfony there are lots of them, i am currently using codeigniter + jquery + knockout and is boosting me a lot. hope this will help you

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!

Categories

Resources