Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New Coder
    Join Date
    Mar 2013
    Posts
    28
    Thanks
    7
    Thanked 0 Times in 0 Posts

    quick database question

    Okay, I'm in a quandry as I'm having to learn as I go to create this training video for my boss. I'm reading and learning all about PHP, but haven't gotten to the part about databases yet, but have to add something that probably requires it ASAP before I get a chance to learn it.

    I'm hoping there's an easy way to accomplish this without getting into database stuff.

    It's a training video with questions and we need a way for those who are learning and taking the tests to prove they completed it. My plan was for a simple form field at the end for them to type their name in which will get permanently added to a page the boss has access to. That way he will have a permanent list online of everyone who has completed it.

    Any thoughts?

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,543
    Thanks
    80
    Thanked 4,617 Times in 4,581 Posts
    If you *can* get away with something as simple as you describe (type in their name when the video is finished playing...but how do you know they didn't simply fast forward through 98% of the video??? seems horribly inadequate to me) then why do you need a database?

    Just use a text file and append each name as a line to the text file.

    But, really, shouldn't you AT LEAST give the users a multiple choice quiz and records their names as well as their scores on the quiz? You could still do that with just a text file, no DB needed.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,474
    Thanks
    63
    Thanked 537 Times in 524 Posts
    You need to go to tizag.com and take a crash course in using mysql.

    Seriously it's not as complicated as you might think. Once you have the basics it's very easy to use and you will find it much easier to work with, store and retrieve data.
    I can't really think of anything to write here now...

  • #4
    New Coder
    Join Date
    Mar 2013
    Posts
    28
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    If you *can* get away with something as simple as you describe (type in their name when the video is finished playing...but how do you know they didn't simply fast forward through 98% of the video??? seems horribly inadequate to me) then why do you need a database?

    Just use a text file and append each name as a line to the text file.

    But, really, shouldn't you AT LEAST give the users a multiple choice quiz and records their names as well as their scores on the quiz? You could still do that with just a text file, no DB needed.
    Thanks for the response. Yes, there is a quiz after each video and you can't go to the next page without getting every question right. If you get a question wrong you have to start over again from the beginning.

    Okay, so the text file sounds good. How do I do that? (is there a link to a page somewhere that teaches that very thing?)

  • #5
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    891
    Thanks
    174
    Thanked 102 Times in 102 Posts
    Okay, so the text file sounds good. How do I do that? (is there a link to a page somewhere that teaches that very thing?)
    As tangoforce mentioned check out tizag.com

    PHP Tutorial - File Write

    then read up on fileappend

    LT
    "The greatest revenge is to accomplish what others say you cannot do."
    ~ Unknown

    I used to be indecisive, but now I'm not so sure.

  • Users who have thanked low tech for this post:

    hoodleehoo (07-22-2014)

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,543
    Thanks
    80
    Thanked 4,617 Times in 4,581 Posts
    All you really need to know is in the PHP documentation:
    PHP: fopen - Manual
    PHP: fwrite - Manual

    Though the fileappend page on that site Low Tech gave gives a compete example.
    Last edited by Old Pedant; 07-22-2014 at 02:52 AM.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    hoodleehoo (07-22-2014)

  • #7
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,474
    Thanks
    63
    Thanked 537 Times in 524 Posts
    I wouldn't even bother with those - one function is ALL you need:

    PHP: file_put_contents - Manual

    That deals with all the file handles, locks, opening, closing etc internally.
    I can't really think of anything to write here now...

  • Users who have thanked tangoforce for this post:

    hoodleehoo (07-22-2014)

  • #8
    New Coder
    Join Date
    Mar 2013
    Posts
    28
    Thanks
    7
    Thanked 0 Times in 0 Posts
    THanks everyone for your help! I think the file_put_contents will work wonderfully!

    I have another question though. I can't have people just going to the final page without actually going through the video so I'm trying to use _session to do it.

    The simplest thing I could think of is to actually define $_session = 1 at the beginning of the second page and then carry that value through the test and every page will look for that. If it sees that $_session is blank or = 0 it won't run the page but instead say they have to start from the beginning. Then any time they get a wrong answer they'll get a message saying they need to start over and either the session will be destroyed or $_session will be redefined as = 0.

    The last page will also check to make sure $_session = 1 or it won't input the name into the file.

    My question is that I don't know how to carry over the $_session variable from page to page. I thought if I just started the session at the top of each page that it would automatically carry over, but I guess that's not the case? I really hope it's not difficult! :-/

  • #9
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,474
    Thanks
    63
    Thanked 537 Times in 524 Posts
    You can't use $_session and set it to one because the session array is just that - an array. This means you can set / get a value directly, you must store your value as an indexed array item - eg $_SESSION['my_key_name'] = 1;

    Also please note that it's actually $_SESSION - all uppercase. If you want php to remember these values between php scripts you MUST use $_SESSION - all caps as this is the ONLY super global array that will be made available (along with _GET and _POST. Yes there is a distinct difference between $_SESSION and $_session - the uppercase version is part of php sessions, the lower case will be a variable that you've created and will not be part of the session that php remembers.

    You will also need to use session_start() at the top of your script before ANY output.

    As for the rest of your post, sorry I'm not going to comment. I've told you to take a crash course at tizag and you're determined to ignore so there is little point me helping further!
    I can't really think of anything to write here now...

  • Users who have thanked tangoforce for this post:

    hoodleehoo (07-22-2014)

  • #10
    New Coder
    Join Date
    Mar 2013
    Posts
    28
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Thanks, that did the trick! I'm sorry I didn't respond to your suggestion of tizag. I only saw it in one post, but I'm not sure what it is. I don't have time to learn a program at the moment. I assume it's some kind of framework?

  • #11
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,474
    Thanks
    63
    Thanked 537 Times in 524 Posts
    You assume wrong and that will trouble you in the future.

    Why would I recommend tizag.com and tell you to take a crash course in using a database there at that website?

    Anyway good luck with your project!
    I can't really think of anything to write here now...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •