Monk Friends, I have a cgi which generates a html form and then gets data from a DBI query. I have setup a check_box and am setting some flags based on the boxes enabled. Everything in my script is working except the if statement. Please check if(($new_flag =1) && ... in the code. I am perplexed as hell. Please help! Regards, Rakhee
#!/usr/bin/perl -w # # # This is the HTML form for selecting projects for QA Metrics # use lib qw(/tools/local/lib/perl5); use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); use DBI; use GD::Graph::linespoints; $cgi= new CGI; if (!$cgi->param) { print $cgi->header; print $cgi->start_html(-title=>'Project Selection', -style => {'src'=> +'http://wwwin.telegent.com/sqametrics/style1.css'}); print $cgi->startform; print $cgi->h3('Select Project to view QA Metrics'); print $cgi->br; print $cgi->br; print "<em><b>Enter Start Date [dd/mm/yyyy]</b></em><br>"; print $cgi->textfield(-name=>'start_date', -default=>'07/03/2009', -size=>9, -maxlength=>80); print $cgi->br; print $cgi->br; print "<em><b>Enter End Date [dd/mm/yyyy]</b></em><br>"; print $cgi->textfield(-name=>'end_date', -default=>'08/01/2010', -override=>true, -size=>9, -maxlength=>80); print $cgi->br; print $cgi->br; print $cgi->br; print "<b>Select Project and DataType to View QA Metrics </b><br>" +; print $cgi->br; print $cgi->scrolling_list(-name=>'Projects', -value=>[ 'ARES', 'POSEIDON_SW', 'DEIMOS', 'MIMAS', 'JUPITER', 'POSEIDON', 'DIONYSUS'], -size=>7, -multiple=>'false', -default=>'ARES'); print $cgi->br; print $cgi->br; print $cgi->checkbox_group(-name=>'bug_status', -value=>[ 'new', 'open', 'reopen', 'fixed', 'verified', 'closed'], -default=>['new', 'open', 'reopen','fixed']); print $cgi->br; print $cgi->br; print "<b>Select from P1, P2, or P1+P2 Bugs Data</b><br>"; print $cgi->br; print $cgi->radio_group(-name=>'P1P2_bugs', -values=> ['P1', 'P2','P1-P2'], -default=>['P1'], -linebreak=>'true'); print $cgi->br; print $cgi->submit(-value=>'Submit Project'); print $cgi->endform; print $cgi->end_html; } else { my $start_date = param('start_date'); #my $start_date_newfrmt = &date_format($start_date); my @date_array = split(/\//, $start_date); my $start_date_newfrmt = join('-', @date_array[2], @date_array[1], @da +te_array[0]); my $end_date = param('end_date'); my @date_array1 = split(/\//, $end_date); my $end_date_newfrmt = join('-', @date_array1[2], @date_array1[1], @da +te_array1[0]); my @selected = param('Projects'); my @turned_on = param('bug_status'); my $num_data_on = @turned_on; #print "Content-type: text/html\n\n"; #print @selected[0], @turned_on[0], $num_data_on; my $which_radio_button = param('P1P2_bugs'); # #Decide the rec_type based on the Radio button selection if ($which_radio_button eq 'P1') { $rec_type= '3'; $y_label = 'Open P1 Bugs'; } elsif ($which_radio_button eq 'P2') { $rec_type = '4'; $y_label = 'Open P2 Bugs'; } elsif ($which_radio_button eq 'P1-P2') { $rec_type = '2'; $y_label = 'Open P1-P2 Bugs'; }; my $project_name1 = @selected[0]; my $num_selected = @selected; # # Check what data types are selcted and set flags for plotting the dat +a # my $new_flag =0; my $open_flag =0; my $reopen_flag = 0; my $fixed_flag = 0; my $verified_flag = 0; my $closed_flag = 0; if($num_data_on eq 0) { print "Content-type: text/html\n\n"; print "Please select at least one Data type"; } else { foreach $data_type (@turned_on) { if ($data_type eq "new") { $new_flag = 1;} if ($data_type eq "open") { $open_flag = 1;} if ($data_type eq "reopen") { $reopen_flag = 1;} if ($data_type eq "fixed") { $fixed_flag = 1;} if ($data_type eq "verified") { $verified_flag = 1;} if ($data_type eq "closed") { $closed_flag = 1;} } } #print "Content-type: text/html\n\n"; #print @selected[0],@turned_on[0], $new_flag, $open_flag, $reopen_flag +, $closed_flag; if ($num_selected eq 1) { # if (@selected[0] eq "ARES") { my $dbh = DBI->connect('dbi:mysql:bugz:bugzilla.telegent.com:3306', 's +wqa', 'sImANten') or die "Connection Error: $DBI::errstr\n"; my $sql = "Select log_date, new_cnt, open_cnt, reopen_cnt, fixed_cnt, +verified_cnt, closed_cnt from swqa.Poseidon where product like '%$pro +ject_name1%' and rec_type='$rec_type' and log_date between '$start_da +te_newfrmt' and '$end_date_newfrmt'"; my $sth = $dbh->prepare($sql); $sth->execute or die "SQL Error: $DBI::errstr\n"; my @log_date = (); my @new_bugs = (); my @open_bugs = (); my @reopen_bugs = (); my @fixed_bugs = (); my @verified_bugs = (); my @closed_bugs = (); while (my @row = $sth->fetchrow_array) { # print "<tr><td>$row[0]</tr></td><tr><td>$row[1]</td></tr><tr>< +td>$row[2]</tr></td>\n"; push @log_date, $row[0]; push @new_bugs, $row[1]; push @open_bugs, $row[2]; push @reopen_bugs, $row[3]; push @fixed_bugs, $row[4]; push @verified_bugs, $row[5]; push @closed_bugs, $row[6]; } # print @log_date; # print @deimos_open_bugs; $dbh->disconnect; #print "Content-type: text/html\n\n"; #print $new_flag, $open_flag, $reopen_flag, $fixed_flag; # if (($new_flag = 1) && ($open_flag = 1) && ($reopen_flag = 1) && ($fix +ed_flag = 1)) { my @data = (\@log_date, \@new_bugs, \@open_bugs, \@reopen_bugs, \@ +fixed_bugs, \@verified_bugs, \@closed_bugs);} print $cgi->header( -type => 'image/png'); my $title = "Open Bugs for $project_name1"; my $mygraph = GD::Graph::linespoints->new(600, 400); #my @legend_keys = qw(new_bugs open_bugs reopen_bugs fixed_bugs verifi +ed_bugs ); my @legend_keys = qw(new_bugs open_bugs reopen_bugs fixed_bugs verifie +d_bugs closed_bugs); $mygraph->set( x_label => 'Log_Date', y_label => $y_label, x_label_skip => 30, x_labels_vertical => true, title => $title, legend_placement => 'BL', legend_marker_height => 12, dclrs => [ qw(green blue red yellow brown orange) ], ) or warn $mygraph->error; $mygraph->set_legend(@legend_keys); $mygraph->set_title_font('/fonts/arial.tf', 24); # # Create Data per turned on Data Types #print $num_selected; #} elsif (($new_flag eq 1) && ($open_flag eq 1) && ($reopen_flag eq 1) + && ($fixed_flag eq 1) && ($verified_flag eq 1)) { # my @data = (\@log_date, \@new_bugs, \@open_bugs, \@reopen_bugs, \ +@fixed_bugs, \@verified_bugs ); #} elsif (($new_flag = 1) && ($open_flag = 1) && ($reopen_flag = 1) && + ($fixed_flag = 1)) { # my @data = (\@log_date, \@new_bugs, \@open_bugs, \@reopen_bugs, \ +@fixed_bugs ); #} elsif (($new_flag eq 1) && ($open_flag eq 1) && ($reopen_flag eq 1) +) { # my @data = (\@log_date, \@new_bugs, \@open_bugs, \@reopen_bugs); #} elsif (($new_flag eq 1) && ($open_flag eq 1)) { # my @data = (\@log_date, \@new_bugs, \@open_bugs); #} elsif (($new_flag eq 1)) { # my @data = (\@log_date, \@new_bugs); #} #print "Content-type: text/html\n\n"; #print @data; #if (($new_flag = 1) && ($open_flag = 1) && ($reopen_flag = 1) && ($fi +xed_flag = 1)) { # my @data = (\@log_date, \@new_bugs, \@open_bugs, \@reopen_bugs, \ +@fixed_bugs );} # my @data = (\@log_date, \@new_bugs, \@open_bugs, \@reopen_bugs, \ +@fixed_bugs, \@verified_bugs, \@closed_bugs); my $myimage = $mygraph->plot(\@data) or die $mygraph->error; binmode STDOUT; print $myimage->png; #my $mygraph #print $cgi->end_html; } } sub date_format($date){ my @date_array = split(/\//, $date); print @date_array; my $new_date = join('-', @date_array[2], @date_array[1], @date_arr +ay[0]); return $new_date; }

In reply to my if statement is not working?! by rakheek

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.