I've made a very very simple quiz game in my spare time and basically the quiz poses a number of questions and when the quiz is done you get a score. I'd like for this score to be saved but I don't want to use a database to store them. Is it possible to store it in a .txt
file or something like that? I have ONLY used html and JavaScript for this game (and some CSS) but I haven't used PHP and would like to avoid it at all costs.

- 25,759
- 11
- 71
- 103

- 5,187
- 13
- 34
- 49
-
Oooh, yes, it *is* possible to store data in a text file: http://stackoverflow.com/questions/585234/how-to-read-and-write-into-file-using-javascript – Cilan Dec 24 '13 at 17:30
-
What language are you planning to use server side ? If you only know JavaScript and are willing to learn, you might want to look for nodejs. Once you have a language and you know how to use it, you'll be better able to choose between raw text file or database or other. – Denys Séguret Dec 24 '13 at 17:30
-
“I haven't used PHP and would like to avoid it at all costs.” So you want to store data in a text file but you don’t want to use PHP? – Giacomo1968 Dec 24 '13 at 17:30
-
Yes Jake, I'm wondering if this is possible. I do know some php. – Sam Creamer Dec 24 '13 at 17:31
-
txt, xml, csv lots of choices here. – xQbert Dec 24 '13 at 17:31
-
Please clarify what you mean by "stored" -- on the user's device, or on the server? – Daniel Dec 24 '13 at 17:34
-
on the server, from the vibes I'm getting I assume I'm going to have to use php. I think I'll just use a callback function to store them in a .txt file. – Sam Creamer Dec 24 '13 at 17:34
4 Answers
If you are just storing the score to reuse it on the page for that user, you can store it in a cookie. This can be done with JavaScript. http://www.quirksmode.org/js/cookies.html Be aware that a user can modify the cookie to change his saved score.
If you want to store the value on the server, you will need to use some programming language on the server. There are many alternatives to PHP (e.g.: Python, Ruby, Perl).

- 136
- 7
I haven't used PHP and would like to avoid it at all costs.
So you want to store data in a text file but you don’t want to use PHP? How do you expect to save the data?
I would then recommend you use a pre-packaged CMS framework like WordPress. Yes it uses MySQL & PHP, but you do not have to be a PHP or MySQL expert to use it. And for what you describe, it sounds like this would be the best way for you to implement this application without learning much beyond WordPress basics.

- 25,759
- 11
- 71
- 103
-
1Thanks for the response, I think my question was maybe unclear. I haven't used PHP at all in the writing of this small quiz game. I have used PHP. I think someone else worded it better, I'm just looking to write/read from a file. – Sam Creamer Dec 24 '13 at 17:33
-
@SamCreamer Fair enough. But your question is just worded oddly then. – Giacomo1968 Dec 24 '13 at 18:38
You could use a modification of the function I used on my website, I guess. You end up storing a bunch of information in a function, and returning different results based on the calls to that function. Messy, jerry-rigged, but functional. I wouldn't recommend it for a BIG quiz game, but if you're going to use text files you're already being inefficient about it.
If you're planning on storing more than about 20 questions and answers I suggest you upgrade to a database.
function SwitchGroup(mainImage,largeFile,series)
{
document.getElementById(mainImage).src = largeFile;
document.getElementById(mainImage).rel = series;
var currdir = './glass/images/';
Anchor1 = document.getElementById('MainGallAnchorOne');
Anchor2 = document.getElementById('MainGallAnchorTwo');
Anchor3 = document.getElementById('MainGallAnchorThree');
Anchor4 = document.getElementById('MainGallAnchorFour');
Anchor5 = document.getElementById('MainGallAnchorFive');
Anchor6 = document.getElementById('MainGallAnchorSix');
if (series == 'series01')
{
// Messy, yes. But the data is all specific
Anchor1.href = currdir + 'series01/series0101big.jpg';
Anchor2.href = currdir + 'series01/series0102big.jpg';
Anchor3.href = currdir + 'series01/series0103big.jpg';
Anchor4.href = currdir + 'series01/series0104big.jpg';
Anchor5.href = currdir + 'series01/series0105big.jpg';
Anchor6.href = currdir + 'series01/series0106big.jpg';
Anchor1.title = 'Series 1';
Anchor2.title = 'Large Blue Bowl (m) (1)';
Anchor3.title = 'Blue Amphora (m)';
Anchor4.title = '14-16';
Anchor5.title = 'Aubergine Pitcher (m)';
Anchor6.title = 'Green and White and Twisty (m)';
Anchor1.rel = 'lightbox[series01]';
Anchor2.rel = 'lightbox[series01]';
Anchor3.rel = 'lightbox[series01]';
Anchor4.rel = 'lightbox[series01]';
Anchor5.rel = 'lightbox[series01]';
Anchor6.rel = 'lightbox[series01]';
}
if (series == 'series02')
{
Anchor1.href = currdir + 'series02/series0201big.jpg';
Anchor2.href = currdir + 'series02/series0202big.jpg';
Anchor3.href = currdir + 'series02/series0203big.jpg';
Anchor4.href = currdir + 'series02/series0204big.jpg';
Anchor5.href = currdir + 'series02/series0205big.jpg';
Anchor6.href = currdir + 'series02/series0206big.jpg';
Anchor1.title = 'Series 2 - Big Red and Orange Bowl (m)';
Anchor2.title = 'Crackled White and Black Bowl fading to Purple (m)';
Anchor3.title = 'Sparkly, Reduced, and odd (m)';
Anchor4.title = 'Spring Leaf (m)';
Anchor5.title = "My Sister's Christmas Present (m)";
Anchor6.title = 'Ornamental';
Anchor1.rel = 'lightbox[series02]';
Anchor2.rel = 'lightbox[series02]';
Anchor3.rel = 'lightbox[series02]';
Anchor4.rel = 'lightbox[series02]';
Anchor5.rel = 'lightbox[series02]';
Anchor6.rel = 'lightbox[series02]';
}
}

- 2,089
- 1
- 19
- 36