How to save file from "simple database script" to a file?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • auniqbal
    New Member
    • Feb 2011
    • 3

    #1

    How to save file from "simple database script" to a file?

    Hi, I am suing the "simple database script" from this website: http://bytes.com/serversidescrip ting/perl/tutorials/asimpledatabase program/index.html

    See also file attached here.

    I can run the script fine from my Apache server but when I enter the record it says "Error - No Record Added "

    in order to run, I had to add "-w" next to the #!/usr/bin/perl statement, so now syntax is:

    #!/usr/bin/perl -w

    Is there any restrictions or limitations on the script?

    Cheers, Mario :)
    Attached Files
  • RonB
    Recognized Expert Contributor
    • Jun 2009
    • 589

    #2
    It's sad to say, since that script is sponsored/promoted by this forum, but it is very poorly written and my recommendation would be to scrap it and start from scratch.

    If you want to troubleshoot it, the starting point is to look at the sections of code that generate that error message. My guess is that you have a file permissions issue that is preventing the script from updating the file. Unfortunately, the script lacks sufficient and proper error handling that would have alerted you to such problems.

    Ron
    aka FishMonger

    Comment

    • miller
      Recognized Expert Top Contributor
      • Oct 2006
      • 1086

      #3
      Those legacy tutorials were bad even back in 2006 when I joined. It would really help if there was some sort of date on the article if it's going to stay up. At least that way people wouldn't assume the code is still the correct way to do things, if it ever was.

      - Miller

      Comment

      • auniqbal
        New Member
        • Feb 2011
        • 3

        #4
        ok so is there any online tutorial available that teaches to create a simple flat-file database....I have done enough search and couldn't find any yet.

        Comment

        • numberwhun
          Recognized Expert Moderator Specialist
          • May 2007
          • 3467

          #5
          Well, you could start here. And progress through a simple Google search after that.

          Comment

          • auniqbal
            New Member
            • Feb 2011
            • 3

            #6
            hi, even though most of yoy think that given database example is written using best possible approach, but I think it needs a little tweaking to fix it. I have come very close to running it but still it doesnt save data in a file when I click on "Add Record"

            I have checked the following logs in my apache server error logs:


            [Sun Feb 20 19:32:56 2011] [error] [client 192.168.40.1] Odd number of elements in hash assignment at /usr/lib/cgi-bin/db/database.cgi line 65., referer: http://host/
            [Sun Feb 20 19:32:56 2011] [error] [client 192.168.40.1] Use of uninitialized value $form{"action"} in string eq at /usr/lib/cgi-bin/db/database.cgi line 70., referer: http://host/
            [Sun Feb 20 19:32:56 2011] [error] [client 192.168.40.1] Use of uninitialized value $form{"action"} in string eq at /usr/lib/cgi-bin/db/database.cgi line 73., referer: http://host/
            [Sun Feb 20 19:32:56 2011] [error] [client 192.168.40.1] Use of uninitialized value $form{"action"} in string eq at /usr/lib/cgi-bin/db/database.cgi line 76., referer: http://host/
            [Sun Feb 20 19:32:56 2011] [error] [client 192.168.40.1] Use of uninitialized value $form{"action"} in string eq at /usr/lib/cgi-bin/db/database.cgi line 79., referer: http://host/
            [Sun Feb 20 19:32:56 2011] [error] [client 192.168.40.1] Use of uninitialized value $form{"action"} in string eq at /usr/lib/cgi-bin/db/database.cgi line 82., referer: http://host/
            [Sun Feb 20 19:32:56 2011] [error] [client 192.168.40.1] Use of uninitialized value $form{"action"} in string eq at /usr/lib/cgi-bin/db/database.cgi line 85., referer: http://host/
            [Sun Feb 20 19:32:56 2011] [error] [client 192.168.40.1] Use of uninitialized value $form{"action"} in string eq at /usr/lib/cgi-bin/db/database.cgi line 88., referer: http://host/
            [Sun Feb 20 19:32:56 2011] [error] [client 192.168.40.1] Use of uninitialized value $form{"action"} in string eq at /usr/lib/cgi-bin/db/database.cgi line 91., referer: http://host/
            [Sun Feb 20 19:32:56 2011] [error] [client 192.168.40.1] Use of uninitialized value $form{"action"} in string eq at /usr/lib/cgi-bin/db/database.cgi line 94., referer: http://host/
            [Sun Feb 20 19:32:56 2011] [error] [client 192.168.40.1] Use of uninitialized value $form{"action"} in string eq at /usr/lib/cgi-bin/db/database.cgi line 97., referer: http://host/
            [Sun Feb 20 19:32:56 2011] [error] [client 192.168.40.1] Use of uninitialized value $form{"action"} in string eq at /usr/lib/cgi-bin/db/database.cgi line 102., referer: http://host/







            [Sun Feb 20 19:33:27 2011] [error] [client 192.168.40.1] print() on closed filehandle NUM at /usr/lib/cgi-bin/db/database.cgi line 159., referer: http://192.168.40.153/db/database.cgi?action=addrecord
            [Sun Feb 20 19:33:27 2011] [error] [client 192.168.40.1] print() on closed filehandle DATABASE at /usr/lib/cgi-bin/db/database.cgi line 245., referer: http://192.168.40.153/db/database.cgi?action=addrecord

            Thanks for answering my questions :)
            Cheers :)

            Comment

            • numberwhun
              Recognized Expert Moderator Specialist
              • May 2007
              • 3467

              #7
              I would first concentrate on this:

              Odd number of elements in hash assignment at /usr/lib/cgi-bin/db/database.cgi line 65.

              That error says that your hash assignment is missing something. Hashes are lists of key=>value pairs. You must have pairs for the assignment. Lack of a pair would throw that error. I would also recommend you turn on the "use strict;" pragma at the beginning of your script and clean up what it finds as well.

              Out of curiosity, why not just use a database like mysql, instead of using a flat file? Using a flat file is not nearly as efficient as a regular database and it has its limitations.

              Regards,

              Jeff

              Comment

              Working...