in reply to Perl: info from database into a form(HTML)

So, what code have you written and where exactly do you encounter problems?

Most of what you want should be easily achievable by using DBI and CGI, but unless you tell us where exactly you encounter problems, we can't help you much.

  • Comment on Re: Perl: info from database into a form(HTML)

Replies are listed 'Best First'.
Re^2: Perl: info from database into a form(HTML)
by alen129 (Novice) on Jul 29, 2016 at 20:57 UTC
    Thank you for trying to help me.

    I have the HTML button and the SQL statmenet ready but dont know where to go from here?

    **HTML:** print " <div style=\"z-index:86;\" class=\"group-shell\">"; print " <table>\n"; print " <tr><td><input class=\"dial-red-button\" id=\"importFrom +CAD\" type=\"submit\" value=\"Import Info\"></td></tr>\n";

    **javascript-jquery**

    <script type="text/javascript">

    \$(document).ready(function() {

    \$('#importFromCAD').click(function () {

    \$('#importNav').val('');

    return true;

    **Perl SQL statement:**

    $sql_statement20 = "select * FROM CT_AL_CAD_ID where CAD='$CAD' ORDER BY KeyField DESC";

    $sth20 = $dbh->prepare($sql_statement20);

    $sth20->execute();

    $sth20->bind_columns(undef, \$ID_data[0], \$ID_data1, \$ID_data2, \$ID_data3, \$ID_data4, \$ID_data5, \$ID_data6, \$ID_data7, \$ID_data8, \$ID_data9, \$ID_data10, \$ID_data11, \$ID_data12);

    $sth20->fetch();

      This is really where I'm stuck at and have no clue how to proceed, how do I display the retrieved info from the database to the user in the form fields so it can be modified without the info being submitted to the second database first.

        You will need two functions in your Perl program:

        1. Display a row to the user for editing
        2. Save a row to the new database after editing

        So, I would introduce an URL parameter, say, action, which is either display (or empty) for the display action and save for the save action. Output something like the following HTML in the display action:

        <input type="hidden" name="action" value="save">

        You will likely also want to offer the user an option to reset their input:

        <a href="?action=display;row=$current_row_identifier">Reset changes</a +>

        You decide which part of your program to execute based on the action value:

        my $action = param('action') || 'display'; if( $action eq 'save' ) { ... } elsif( $action eq 'display ) { ... } else { # Weird error };

        Personally, I would look into Mojolicious or Dancer for doing the scaffolding of the web part of the application, but as they both are frameworks, you will have to learn some stuff not tightly related to creating the HTML and talking to the database. It is also quite feasible to do all you need with just Perl and print statements for the HTML generation.