Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Perl + MySQL Driven page

by magikman (Initiate)
on Jan 12, 2008 at 19:08 UTC ( [id://662093]=perlquestion: print w/replies, xml ) Need Help??

magikman has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I would first like to thank everyone for their help so far, i really appreciate it. Well, i have been learning perl for my job now for about three weeks. Things have gone pretty well so far. I have written a few scripts here and there. However, i have a much larger project that i have to write a page for. The page needs to have a mysql backend and a perl frontend. It will be used for keeping track of vlan ids and the IP addresses associated with them, also with a 25 char description field. Now, i have created the database with the columns of vlanid, ipaddr, and descr. The vlanid and ipaddr are of data type int while descr is of type varchar(25). I have written a small perl script that is able to insert and print out the fields in the database into a html table. Now, i am quite new to web programming, so i am unsure how to actually approach the project, this is where i need your help. How should i approach this issue? Should i write separate pages for displaying the data, inserting and deleting the data? Should i have this all on one page? Where should i go from here? Do any of you know of a GOOD book that i can get on the subject that will help me? Any advise will be beneficial. Thanks!!

Replies are listed 'Best First'.
Re: Perl + MySQL Driven page
by bradcathey (Prior) on Jan 12, 2008 at 20:07 UTC

    A couple of PMish things first.

    • The formating of your node is not conducive to anyone wanting to read it. Try little things, like paragraphs!
    • Make it clear what your question *really* is, what your goal is, etc.
    • Show us your code so far, and inbetween <code> tags

    Okay, having said that, HTML::Template is your new best friend. For starters, it will allow you to create HTML pages with placeholders for your data, separating the HTML from your Perl. It's nice to compartmentalize the two types of code. There is a nice HTML::Template community and a search of the Monastery, or even Google will turn up all sorts of help. E.g., jeffa's great tutorial.

    When you have some code written, come on back here and give us a looksie, and maybe we can offer more effective help.

    —Brad
    "The important work of moving the world forward does not wait to be done by perfect men." George Eliot
Re: Perl + MySQL Driven page
by igelkott (Priest) on Jan 12, 2008 at 21:32 UTC

    A beginning programmer might think to write separate cgi scripts for each task (display, insert and delete) but I'd prefer a single script to keep it all together to make changes more simple. Call the script with a "mode" argument to trigger the right functions to display the forms and have them react appropriately. Make certain to consider security since this is usually necessary even for an intranet environment.

    Since you already have the Perl-MySQL part done, the documentation for the standard CGI module can probably give you the rest. This includes a few examples to build from.

    If want a recommendation for a book, you might look into the PerlMonks' Reviews, e.g., MySQL and Perl for the Web.

Re: Perl + MySQL Driven page
by leocharre (Priest) on Jan 13, 2008 at 02:26 UTC

    Then first thing you need to do it get yourself a whiteboard. A really big one. Put it on your wall, besides your desk.
    If anybody looks at you funny, ignore them.

    Make yourself a list of the various different things that your interface can do.

    I am going to assume here that this is for intercompany use in a closed network, that is some kind of list management trinket for your organization, that there is no login, etc.
    It's just a web front end (a gui (graphical user interface)) to something.

    For example.

    1)database management
     create database
     drop database (?)
     check database being present
    
    2)querying
     list present records
     insert new record
     replace record
     delete record
    
    3)graphical front end
     display present records as html
     display option to insert new record (form html)
     give feedback about new record (success or fail)
    

    Now, let's give namespaces to these things, what should the subs be named?
    (Remember, you are still usinng the whiteboard. Your computer is off.)

    # this is PSEUDOCODE # DATABASE SETUP & MANAGEMENT sub database_create {} sub database_check_exists {} sub database_create_tables {} sub database_drop {} # DATABSE QUERYING / INTERACTION # there is NO html here, this is just code sub record_new {} sub record_delete {} sub records {} # returns ids for all records present sub record_get{} sub record_replace { #this may or may not be how you want to 'replace' record_delete($id) record_insert($id,{ vlanid => $vlanid, ipaddr => $ipaddr, descr => $descr }); } # GRAPHICAL INTERFACE sub show_records { my @records = records() ; for(@records){ record_get() etc etc }

    What I'm trying to get at is that you should plan out everything. And that you should separate everything. This is not php, the human interface element is the last thing to address.

    You want to separate what your code does with the idea of interaction, the html. This is very important. Your application should be able to get tested, without using a web browser.

    Consider developing a test suite, tests.

    If you are looking to maybe coding perl for your career, you will learn to use tests.

    Later on.. after you know this material.. you will likely be using CGI::Application for something like this.

Re: Perl + MySQL Driven page
by twotone (Beadle) on Jan 13, 2008 at 07:22 UTC

    I got my start learning perl and perl/mysql programming from the book "CGI Programming 101." The book is available, including the first several chapters for free online, here:

    http://www.cgi101.com/book/

Re: Perl + MySQL Driven page
by andyford (Curate) on Jan 14, 2008 at 23:01 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://662093]
Approved by graff
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-24 21:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found