Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Hi to all community, I'm stuck and now I have feeling that my script contains two types of errors, for some of them I have enough of experience to see and fix, and some of them I'm even unable to see, so I want to ask for help. I want to build a cgi that checks out a DB builds a table and provides buttons\checkboxes\etc for different modifications. I have a cgi for editing of this table and it works if I'm using it manually like: http://127.0.1.1/puppeteer/edit.cgi?mode=stats&field=site&value=test1.test.com At this time I'm trying to make a call an "edit.cgi" by clicking "Edit" button, and it's not working.

main.cgi

#!/usr/bin/perl -wT use strict; use warnings; use DBI; use CGI qw(:standard); use Date::Format; use HTML::Template; my (@keys,@values,@env_types,@servers,@loopdata); my %rowdata; my ($env_types); my $o_dbuser = "test"; my $o_dbpwd = "test"; my $cgi = CGI->new(); my $mode = $cgi->param('mode') || 'show'; my $dbh = DBI->connect("DBI:mysql:database=overall;host=10.10.10.10;po +rt=3306", "$o_dbuser", "$o_dbpwd", {'RaiseError' => 1}); my $env_types = "SHOW TABLES FROM `overall` LIKE '%xen_env_%';"; my $sth = $dbh->prepare($env_types); $sth->execute() or die "could not execute", $sth->errstr; while (my $e = $sth->fetchrow_array) { push @env_types, $e; } $sth->finish(); my $get_servers = "SELECT `serverid` FROM `Servers`;"; my $sth0 = $dbh->prepare($get_servers); $sth0->execute(); while (my $s = $sth0->fetchrow_array()) { push @servers, $s; } $sth0->finish(); if ($mode eq 'servers') { my (@fields); my $get_summary = "SELECT * FROM `Servers`;"; my $sth0 = $dbh->prepare($get_summary); $sth0->execute(); @keys = @{$sth0->{NAME_lc}} or die "Can't get Field names due +to:$!"; $sth0->finish(); push @fields, "<th BGCOLOR=\"\#FFFFFF\">flag</th>\n"; push @fields, "<th BGCOLOR=\"\#C8C8E8\"> </th>\n"; for (@keys) { push @fields, "<th BGCOLOR=\"\#C8C8E8\"><TMPL_VAR NAME +=$_></th>\n"; } for (@keys) { if ($_ eq "serverid") { push @values,"<tr><td align=\"center\"><input +type=\"checkbox\" name=\"choice\" value=\"<TMPL_VAR NAME=serverid>\"> + </td>\n"; push @values,"<form action=\"edit.cgi\" method +=\"get\"><td align=\"center\" BGCOLOR=\"\#BFE4FD\" ><input type=\"sub +mit\" name=\"mode\" value=\"edit\"></td></form>\n"; } push @values, "<td width=15% align=\"center\" BGCOLOR= +\"\#BFE4FD\" border-style=solid white><TMPL_VAR NAME=$_></td>\n"; } open (TMPL,">", "/tmp/servers.tmpl"); print TMPL <<SERVERS; <html> <head> <style type="text/css"> p {font-size: 20pt; font-family: "times new roman"; bo +rder-style:solid ; border-width:1px;} p.one {font-size: 8pt; font-family: "times new roman"; + border-style:solid black;} body { font-family: verdana,arial,sans-serif; font-size: 5pt; } </style> </head> <body> <form> <p class="one"> <table border=0 > <TMPL_LOOP NAME=KEYS> @fields </TMPL_LOOP> <TMPL_LOOP NAME=VALUES> @values </TMPL_LOOP> <table></table> </p> </form> </body> </html> SERVERS close(TMPL); foreach my $key (@keys) { $rowdata{$key} = $key; } push(@loopdata, \%rowdata); my $values; $get_summary = "SELECT * FROM `Servers`;"; $sth0 = $dbh->prepare($get_summary); $sth0->execute(); push @{$values}, $_ while $_ = $sth0->fetchrow_hashref(); $sth0->finish(); my $template = HTML::Template->new(filename => '/tmp/servers.t +mpl', associate => $cgi,); $template->param( KEYS => \@loopdata); $template->param( VALUES => $values); print "Content-Type: text/html\n\n", $template->output; }

HTML generated by my script:

<html> <head> <style type="text/css"> p {font-size: 20pt; font-family: "times new roman"; border-sty +le:solid ; border-width:1px;} p.one {font-size: 8pt; font-family: "times new roman"; border- +style:solid black;} body { font-family: verdana,arial,sans-serif; font-size: 5pt; } </style> </head> <body> <form> <p class="one"> <table border=0 > <th BGCOLOR="#FFFFFF">flag</th> <th BGCOLOR="#C8C8E8"> </th> <th BGCOLOR="#C8C8E8">serverid</th> <th BGCOLOR="#C8C8E8">env_type</th> <th BGCOLOR="#C8C8E8">predicted_capacity</th> <th BGCOLOR="#C8C8E8">used_capacity</th> <th BGCOLOR="#C8C8E8">available_space</th> <th BGCOLOR="#C8C8E8">free_space</th> <th BGCOLOR="#C8C8E8">percents_free</th> <th BGCOLOR="#C8C8E8">daily_load</th> <th BGCOLOR="#C8C8E8">applied_routine</th> <th BGCOLOR="#C8C8E8">comments</th> <th BGCOLOR="#C8C8E8">check_date</th> <tr><td align="center"><input type="checkbox" name="choice" va +lue="xen1-test1"> </td> <form action="edit.cgi" method="get"><td align="center" BGCOLOR="#BFE +4FD" ><input type="submit" name="mode" value="edit"></td></form> <td width=15% align="center" BGCOLOR="#BFE4FD" border-style=solid whi +te>xen1-test1</td> <td width=15% align="center" BGCOLOR="#BFE4FD" border-style=solid whi +te>xen_env_app</td> <td width=15% align="center" BGCOLOR="#BFE4FD" border-style=solid whi +te>500</td> <td width=15% align="center" BGCOLOR="#BFE4FD" border-style=solid whi +te>0</td> <td width=15% align="center" BGCOLOR="#BFE4FD" border-style=solid whi +te>0</td> <td width=15% align="center" BGCOLOR="#BFE4FD" border-style=solid whi +te>0</td> <td width=15% align="center" BGCOLOR="#BFE4FD" border-style=solid whi +te>0</td> <td width=15% align="center" BGCOLOR="#BFE4FD" border-style=solid whi +te>0</td> <td width=15% align="center" BGCOLOR="#BFE4FD" border-style=solid whi +te>0</td> <td width=15% align="center" BGCOLOR="#BFE4FD" border-style=solid whi +te>None</td> <td width=15% align="center" BGCOLOR="#BFE4FD" border-style=solid whi +te>2012-08-22</td> <tr><td align="center"><input type="checkbox" name="choice" va +lue="xen1-test2"> </td> <form action="edit.cgi" method="get"><td align="center" BGCOLOR="#BFE +4FD" ><input type="submit" name="mode" value="edit"></td></form> <td width=15% align="center" BGCOLOR="#BFE4FD" border-style=solid whi +te>xen1-test2</td> <td width=15% align="center" BGCOLOR="#BFE4FD" border-style=solid whi +te>xen_env_app</td> <td width=15% align="center" BGCOLOR="#BFE4FD" border-style=solid whi +te>500</td> <td width=15% align="center" BGCOLOR="#BFE4FD" border-style=solid whi +te>486</td> <td width=15% align="center" BGCOLOR="#BFE4FD" border-style=solid whi +te>492</td> <td width=15% align="center" BGCOLOR="#BFE4FD" border-style=solid whi +te>211</td> <td width=15% align="center" BGCOLOR="#BFE4FD" border-style=solid whi +te>43</td> <td width=15% align="center" BGCOLOR="#BFE4FD" border-style=solid whi +te>904</td> <td width=15% align="center" BGCOLOR="#BFE4FD" border-style=solid whi +te>0</td> <td width=15% align="center" BGCOLOR="#BFE4FD" border-style=solid whi +te>None</td> <td width=15% align="center" BGCOLOR="#BFE4FD" border-style=solid whi +te>2012-08-21</td> <table></table> </p> </form> </body> </html>

So from my point of view I see following problems:

1. What type of requests should I use POST\GET and how I should change my scripts in order to make them work in a same way? (I'm using CGI)

2. Clicking on "Edit" button I'm getting: http://127.0.1.1/puppeteer/main.cgi?... instead of http://127.0.1.1/puppeteer/edit.cgi?... defined on action="edit.cgi" of a form tag. Can anyone tell why this is happening?

<form action="edit.cgi" method="get"><td align="center" BGCOLOR="#BFE4FD" ><input type="submit" name="mode" value="edit"></td></form>

In reply to .cgi interaction problems by kazak

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (5)
    As of 2014-09-21 20:49 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (176 votes), past polls