in reply to Re: PLEASE Help with this script
in thread PLEASE Help with this script

The script is supposed to create a txt file and write the data from the form to the page. But it is only creating the PO.txt file and not storing any info. The page is blank. also, when the customer logs in again of course there's no info to show up in the fields that they've filled out already. I've spent so much time on this and I have even used a working script and tried to edit it to create the page but it just comes out all messed up. I'd be willing to pay someone to fix this among other issues I'm having with this application. I am a web developer and I've never done anything more than a simple email form in cgi.

Replies are listed 'Best First'.
Re^3: PLEASE Help with this script
by Corion (Patriarch) on Dec 16, 2009 at 22:00 UTC

    You're not using strict, and the script is a horrible mess. I suggest a complete rewrite.

    At least the empty file will likely come from $write_data not being what you think it is. It is assigned to by this line of code:

    $write_data="$${paramname}:::";

    ... and I don't even want to track down to what global variable name is stored in $paramname and where it is then dereferenced to.

      Thank you so much for your help! You just proved to me that I need to pass this project on to someone that knows what they are doing. I give up.
Re^3: PLEASE Help with this script
by ksolomon (Initiate) on Dec 16, 2009 at 22:01 UTC
    Here is a page from the app that is working, I just don't see what I'm doing wrong.
    #!/usr/bin/perl ###################################################################### +###### # S U B R O U T I N E S ###################################################################### +###### ######################################################## sub valid_cookie{ $flag=0; my $session_file=$companyrepository."/session.txt"; #file where se +ssions are stored unless(open(INTT, "$session_file")){print "Session not found $sess +ion_file. $cookie<br>";} while (<INTT>){ #find existing cookie if($_=~/^$cookie\;/){#if cookie exist $flag=1; last; } } close INTT; return $flag; } ###################################################################### +###### sub writeData { my $j=0; open (OUT,">".$datafile); # Print header foreach $head (@header_names){ print OUT "$head\t"; } print OUT "\n"; # Print data $i=0; # $i represents each row + + for ($i=0;$i<=$#write_data;$i++){ for ($j=0;$j<=$#{$write_data[$i]};$j++){ print OUT "$write_data[$i][$j]\t"; } print OUT "\n"; } close (OUT); } ###################################################################### +###### sub readData { my @temp=""; open (IN,"<".$datafile); $i=0; # $i represents each row while (<IN>) { if ($i==0){ # ignore the header $i++; next; }elsif ($_=~/^(.*?)\t/){# read in and split tabs @temp=split("\t", $_); $j=0; foreach $t (@temp){ # each column $j in row $i $read_data[$i-1][$j]="$t"; # store names $j++; } $i++; } } close (IN); } ###################################################################### +###### sub validate_input{ my $p_name=shift; my $p_value=shift; my $vflag=shift; # cosname must contain an aphanumeric character if ($p_name=~/col0/){ if ($p_value!~/[0-9]/){ $vflag=0; } # cosnum must be a digit between 1 and 32767 }elsif($p_name=~/col1/){ if ($p_value!~/[A-Za-z0-9_]/){ $vflag=0; } } return $vflag; } ###################################################################### +###### # E N D S U B R O U T I N E S ###################################################################### +###### ###################################################################### +###### # M A I N ###################################################################### +###### use CGI; $query = new CGI; # initial global variables $repository="/home/warp/userdata/"; $paramcount=0; $formcomplete=1; @header_names=("LATA"); @read_data=(); @read_names=(); @read_cos=(); @data=(); @cos=(); @names=(); $error=""; # pluck out some common params that may have been passed $answer=$query->param("answer"); ####check for valid cookie#### $cookie=""; @temp=""; $cookie=$ENV{'HTTP_COOKIE'}; #identify cookie @temp_cookie=split(';',$cookie); $cookie=$temp_cookie[0]; ($sess_id,$company,$site,$user)=split('%2C', $cookie); $companyrepository=$repository.$company."/".$site; valid_cookie(); # If cookie not valid, then redirect to login page if ($flag==0){print $query->redirect('http://services.genband.com/cgi- +bin/dbq/na/DBQ_welcome.cgi'); }#redirect to another location if ($flag==1){ $dbqfile=$companyrepository."/dbq_finished.txt"; if (-e $dbqfile){ # DBQ has been finished and database has been built print $query->redirect('http://services.genband.com/cgi-bin/dbq/na +/home.cgi'); #redirect to home } } print "Content-type: text/html\n\n"; # create company specific variables $datafile=$companyrepository."/latas.txt"; ################################ # start html $header_file = "header1.html"; open(FILE,"$header_file"); while(<FILE>) { print $_; } close FILE; print <<'ENDHTML'; <tr> <td width="1020" bgcolor="#f4f4f4" align="center"> <table width="900" border="0" cellspacing="0" cellpadding="0"> <tr> <td bgcolor="#232021" height="25px" width="499" align="left" valig +n="bottom"><p class="h1"><a href="DBQ.cgi?tab=1#TabbedPanels1">Call P +rocessing Resources</a> : LATAs</p></td> <td bgcolor="#232021" height="25px" width="401" align="right" vali +gn="bottom"><p class="blinks"><a href="logout.cgi">Logout</a>&nbsp; | + &nbsp;<a href="DBQ_setPW.cgi">Add User</a>&nbsp; | &nbsp;<a href="co +ntact.cgi">Contact</a>&nbsp; | &nbsp;<a href="comment.cgi">Comment</a +></p></td> </tr> <tr><td colspan=2 align=left bgcolor=#ffffff class=border2 class=b +order2> ENDHTML # if the screens file exists then we have already been here once and s +aved valid data, read this data in if (!$answer) { if (-e $datafile){ readData; $formprocessed=1; }else{$formcomplete=0;} } # process passed parameters foreach $paramname ($query->param) { # $paramcount++; $paramvalue=$query->param($paramname); $$paramname=$paramvalue; $$paramname =~ s/\s+/_/g; # place the values in the appropriate array location if ($paramname =~ /row(\d+)col(\d+)/) { # row(i) and column(j) as +read from webpage $match1="$1"; $match2="$2"; $write_data[$1][$2]="$$paramname"; if ($match2==0){ if ($$paramname=~/[0-9]/){ # validate name push @fail, $match1; } } if ($$paramname=~/\D/){ $formcomplete=0; $error="Lata value must be numeric"; } } # print "$paramname, $$paramname, $paramvalue, $$paramvalue<br>"; if (($paramname eq "answer") && ($answer eq "finish")) { $finished=1; } } # trunkate list where Profile names are undefined $len=@fail; @write_data = splice (@write_data, $fail[0], $len); ##################################################################### # if the finish button has been clicked # ##################################################################### ##################################################################### # when entering this page from the main DBQ the answer will be null # ##################################################################### if (($finished) && ($formcomplete)) { writeData; print "<form action=DBQ.cgi?tab=1#TabbedPanels1 method=post>"; print "<p class=status>"; print "The class of service data has been saved. Please click next + to continue. <input type=submit name=answer value=next>"; print "</p>"; # if we are arriving from the main page, a next or re-submit button wa +s clicked, or there # was an error in the form when the finish button was clicked then red +raw the }else{ # if we are here from the main page and this form has been process +ed before then print this message if ($formprocessed) { print "<p class=main>"; print "The Class of Service form has already been processed at + least once, the data last submitted is below.<br><br>"; print "</p>"; } # print instructions print "<p class=status>"; print "In the table below is a list of the termination types that +will be data filled in the switch. "; print "To define a Class of Service, provide a name in the box at +the top of the column and then to the "; print "right of each termination type click the check box to allow + that termination type "; print "for the given screening class. An uncheck box will indicate + that the termination type is to be "; print "blocked for the screening class. For more details click the + help button."; print "</p>"; print "<hr>"; print "<form action='latacfg.cgi' method='post'>"; # present form print "<div style=background-color:#ffffff;overflow:scroll;width:9 +00px;text-align:top;border:1;>"; print "<table cellpadding=0 cellspacing=0 border=0 style=margin:.1 +in;><tr>"; print "<th class=\"mess left_border\" >LATA<span>Specify the LATA +in which you will be providing service.</span></th>"; print "</tr>"; # Print rows for ($i=0;$i<=10;$i++) { print "<tr >"; for ($j=0;$j<=0;$j++){ $type=""; print "<td align=center>"; $paramname="row".$i."col".$j; if ($read_data[$i][$j]){ $type="<input style=text-align:center type=text size=17 maxlen +gth=16 name=$paramname value=$read_data[$i][$j]>"; }else{$type="<input style=text-align:center type=text size=17 +maxlength=16 name=$paramname value=$$paramname>";} print "$type"; print "</td>"; } print "</tr>"; } print "</table></div>"; print "<div style=margin:.2in>"; # initial presentation of the page if ((!$formcomplete) && ($error eq "")) { print "<input type=submit name=answer value=submit>"; print "<button type=button type=button type=button onclick=\"w +indow.location='DBQ.cgi?tab=1#TabbedPanels1'\">"; print "cancel</button> Click 'cancel' to return to Main Menu w +ithout saving your data.<br>"; print "Click 'submit' to proceed with this form."; # errors found when processing }elsif((!$formcomplete) && ($error ne "")){ print "<input type=submit name=answer value='re-submit'>"; print "<button type=button type=button type=button onclick=\"w +indow.location='DBQ.cgi?user=$user&amp;company=$company'\">"; print "cancel</button> $error"; print "Click 'cancel' to return to the Main Menu<br>without sa +ving your data or"; print " please make corrections and click re-submit to proceed + with this form."; # form has been completed without errors }elsif ($formcomplete) { print "<input type=submit name=answer value=re-submit>"; print "<button type=button type=button type=button onclick=\"w +indow.location='DBQ.cgi?tab=1#TabbedPanels1'\">cancel</button>"; print "<input type=submit name=answer value=finish> "; print "The data on the form has been validated. Click 'cancel' + to return to the Main Menu<br>without saving your data,"; print " click 're-submit' to make changes, or click 'finish' to save y +our data and return to the Main Menu."; } print "</form>"; } print "</td></tr>"; print <<'ENDHTML'; </table> </td> </tr> <tr> <td colspan="4" height="25px" bgcolor="#f4f4f4"></td> </tr> <tr> <td colspan="4" height="25px" bgcolor="#F0251A"><p class="h2">&nbs +p;</p></td> </tr> ENDHTML $footer_file = "footer1.html"; open(FILE,"$footer_file"); while(<FILE>) { print $_; } close FILE;