I am confused with looping to stop repeat accurances of a entryies ina log for a report
I am trying to parse a squid log file to let It management know where people are browsing too. my plan block diagram goes a follows 1. open log 2. seperate by IP address , list only one at a time no repeats of the same IP address 3. list only one instance of a visited site , per IP address 4. print HTML file but I guess the best route would be dump each log entry in its own array ( by ip address of client machine) but I am not getting the desired results . I have a file for debuging called scratch.txt here is the code open(LOG,/var/log/squid/access.log); logmess = LOG; close(LOG); open XML log for writing open(LOGXML,/var/log/squid/access.xml); print LOGXML ?xml version=\1.0\?\n; print LOGXML list\n; ## ## open scratch open(scratch,/var/log/squid/scratch.txt); foreach $message(logmess) { chomp($message); fields = split(/\s+/, $message); $time = $fields[0]; $site_visited = $fields[6]; $userip = $fields[2]; $userip1 = $userip; $userip1 =~ s/\./_/g; $xml_ip = $userip1..txt; scratch = test; # dump into array #do loop search foreach $el(scratch){ $found = no; print IP : $xml_ip ... $el\n; if($xml_ip eq $el) { $found = yes; print Yes !!\n; } if($found ne yes) { push(scratch, $xml_ip); } } foreach $rt(scratch){ print scratch $rt\n; } close(scratch); open(XML_IP,$xml_ip); # holding file per IP addresses $fetch = $fields[8]; $type = $fields[9]; # ## Dump each into its own variable ## # visited = split(/\//,$site_visited); # add date , dump into array print XML_IP $userip $visited[2]\n; close(XML_IP); my scratch file looks like this test 192_168_1_68.txt there are more clients that that any suggestions ? thanks Jim
What perl module converts unix time to regular time and date
What perl module converts unix time to regular time and date ? Thanks Jim
get page with IO::Socket , but having trouble saving to file
Hello, get page with IO::Socket , but having trouble saving to file This is what I got: use IO::Socket; $host = www.cnn.com; $document = /newhomepage1.htm; foreach $doc ($document) { $remote = IO::Socket::INET-new( Proto = tcp, PeerAddr = $host, PeerPort = http(80), ); } $EOL = \015\012; $BLANK = $EOL x 2; unless ($remote) { die cannot connect to http daemon on $host } $remote-autoflush(1); #print $remote GET $document HTTP/1.0 . $BLANK; open(LOG9,/var/www/html/bad/bali.txt); print LOG9 $remote \GET $document HTTP/1.0\ . $BLANK; while ( $remote ) { print LOG9 } close $remote; close(LOG9); Help , what am I doing Wrong ?? Jim -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
disable printing an output of a perl script file
I have a quiz program, the script queries the DB and print to the browser a test for the student to take. I would like to prevent them from printing that test. All my clients are IE 6.0 Thanks Jim
Is there a perl module that allows access to Notes on NT box from a Red hat Box
Is there a perl module that allows access to Notes on NT box from a Red hat Box?
I need advise Redhat7.1/MYSQL/PERL updates DB on Lotus Notes on NT box
I need advise Redhat7.1/MYSQL/PERL updates DB on Lotus Notes on NT box, is this project hopeless ? Any Ideas where to start?
help Grading my test
hello , I have a quiz script. I randomly generates questions up to an certain number ( what is ever set in the quiz name settings table) , passes it ina variable to a grade.cgi. the variable looks like this !34!56!5!67! all question numbers seperated by a delimiter. all these questions com from a mysql table. Everything works except for it misses the first question. The script pulls the number , the db doesnt query for the answer, it continues on with the rest of the grading fine. help $dbh =DBI -connect($data_source, $username, $password) or die cant connect to $data_source : my $dbh- errstr\n; while( $questions_asked =~ /!([^!]*)/g) { my $num1 = $1; print this is the number : $num1; # my $sth1 = $dbh - prepare(select * from tests where num = ? ); # i tried these # $sth1 - execute($num1) or die unable to execute query ; # i tried these my $sth1 = $dbh - prepare(select * from tests where num = '$num1'); $sth1 - execute() or die unable to execute query ; #$sth1 - finish; my $array_ref = $sth1 - fetchall_arrayref(); output example t0642k8 Test results for Test : Exchange _ this is the number : 486 486 What two folders are available in Exchange Server? Correct answer is : CE You answered A The Reason this is the number : 564 564 Which bindery attachments does the Internet Mail Service support: Correct answer is : AC You answered The Reason this is the number : 274 274 Which are components of Exchange Server? Correct answer is : BD You answered The Reason this is the number : 43 43 How are schedule free and busy times handled by the Exchange Server? Correct answer is : CYou answered The Reason thanks Jim Flaherty
What am I doing wrong... I want to increment a number in a DB
I have a query to draw it out on my redhat 7.1 box with MySQL 3.23 and I increment it and run update query . Some where it resets back to zero all the time the code foreach $row(@$array_ref) { my($num,$title,$media,$serial,$time,$class,$remarks,$custody,$loc, $format,$qty,$lab,$rew,$sta,$history5,$check) = @$rows; $history2 = $history5; $history2++; } $dbh2 =DBI -connect($data_source, $username, $password); my $sth2 = $dbh2 - prepare(update media1 set history5 ='$history2' where num = '$num'); $sth2 - execute or die unable to execute query ; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Hello all this grading program is still messing up
I have a test maker script , that generates random questions from a DB My grader script needs to grade those same random questions it has a variable that called $questions_asked its output is like this !146!612!145!385!655!34!122!583!119!109 the code #! /usr/bin/perl #user grading script # # May 23, 2002 ver 0.03 require subparseform.lib; Parse_Form; $test = $formdata{'test12'}; $sname = $formdata{'name'}; $date1 = $formdata{'date1'}; $numofques = $formdata{'numofques'}; $questions_asked = $formdata{'admin_test'}; ### # make Page print content-type: text/html\n\n; print html\n; print head\n; print Script Language=\JavaScript\\n; print //--+\n; print // SmartMenus v.1 |\n; print // \©2001 VASIL DINKOV - PLOVDIV, BULGARIA |\n; print // http://mp3.dinkov.com http://mp3.dinkov.com | vasko\@dinkov.com |\n; print //--+\n; print // For Internet Explorer 4 and Netscape 6 |\n; print //--+\n\n; print //==1==Defining Colors\n; print var menuFrameColor=\'#4d4c76\'\;\n; print var menuBgColor=\'#bebddf\'\;\n; print var menuOverBgColor=\'#fff5c6\'\;\n; print var menuFontColor=\'#4d4c76\'\;\n; print var menuOverFontColor=\'#4d4c76\'//(can be the same as menuFontColor)\n\n ; print //==2==Defining TARGET for the links in the menu\n; print var target=\'self\'//(newWindow or self)(cannot navigate to frame)\n\n; print //==3==Defining font, menu cell padding frame border width\n; print var font=\'verdana,arial,helvetica\'\;; print var fontSize=\'10px\'\;\n; print var fontWeight=\'bold\'\;//(bold or normal)\n; print var cellPadding=\'2\'\;\n; print var frameBorderWidth=\'1\'\;\n; print //==4==Defining The Menus Width\n; print var menuWidth=\'140\'\;\n; print //==5==Defining The Menus Placement (top left corner of the menus)\n; print var menuTopPixels=15\;//from document top left corner(without quotes)\n ; print var menu1LeftPixels=0\;\n; print var menu2LeftPixels=74\;\n; print var menu3LeftPixels=144\;\n; print var menu4LeftPixels=226\;\n; print var menu5LeftPixels=296\;\n; print //var menu6LeftPixels=400\;//(if you want more add like this)\n; print //==6==Defining The Menus Count (how many do you want)\n; print var menuCount=2\;//(without quotes)\n; print //=MENU DEFINITIONS=\n; print //(be sure to have the same number of array items for both href text)\n; print //===Menu 1\n; print href1=new Array(\'nam.cgi\',\'addmaterial.cgi\',\'adduser.php\',; print \'\')\;\n; print text1=new Array(\'Add a Patron\',\'Add Material\',\'Add a User\',; print \'Edit a User\')\;\n; print function MV1(){var x=\'\'\;for(i=0\;ihref1.length\;i++); print {x=x+\trtd class=mxz onclick=doGo(\'\+href1[i]+\\'); print onmouseover=ov(this) onmouseout=ou(this)\+text1[i]+\/td; print /tr\}\;return x}\;\n; print //===Menu 1 END \n\n\n; print //===Menu 2\n; print href2=new Array(\'checkout_report.cgi\')\;\n; print text2=new Array(\'Checkout Report\')\;\n\n; print function MV2(){var x=\'\'\;for(i=0\;ihref2.length\;i++); print {x=x+\trtd class=mxz //onclick=doGo(\'\+href2[i]+\\'); print onmouseover=ov(this) onmouseout=ou(this)\+text2[i]+\/td; print /tr\}\;return x}\;\n; print //===Menu 2 END \n\n\n; print //=MENU DEFINITIONS END= \n; print // THE SERIOUS SCRIPT PLEASE DO NOT TOUCH\n; print if(document.all){topY=menuTopPixels}else{topY=menuTopPixels-2}\;; print /*NS bud*/function rV(){q=\'\'\;for(z=1\;z=menuCount\;z++); print {if(document.all){q=q+\m\+z+\.style.display=\'none\'\;\}; print else{q=q+\document.getElementById(\'m\+z+\\').style.display=\'none\'\;\ }}\;return q}\;; print eval(\function hide(a){if(a.clientY=topY){\+rV()+\}}\;; print function hide2(){\+rV()+\}\)\;eval(\function ov(ok); print {ok.style.background=\'\+menuOverBgColor+\\'\;ok.style.; print color=\'\+menuOverFontColor+\\'}\;function ou(ok); print {ok.style.background=\'\+menuBgColor+\\'\;ok.style.; print color=\'\+menuFontColor+\\'}\;function doGo(ok); print {var tgt=\'\+target+\\'\;if(tgt==\'newWindow\'){window.open(ok); print }else{document.location.href=ok}}\;function show(a){if(document.all); print {eval(a).style.display=\'\'}else{document.getElementById(a).style.; print display=\'\'}}\)\;document.write(\style.mxz{font-family:\; print +font+\\;font-size:\+fontSize+\\;color:\+menuFontColor+\\;; print font-weight:\+fontWeight+\\;background:\+menuBgColor+\\;padding:\; print +cellPadding+\\;cursor:default}/style\)\;function buildTheAsses; print (){for(j=1\;j=menuCount\;j++){document.write(\div style=position:; print absolute\;top:\+(menuTopPixels-1)+\\;left:\+(eval(\'menu\'+j+\'; print LeftPixels\')-100)+\\;z-index:3\;display:none id=\+(\'m\'+j); print +\table
FW: Hello all this grading program is still messing up
I am so sorry , I get an output like question this is question 41miss didnt get grade results this is question 52 works you answered a when correct answer is c it will not split the variable $questions_asked and and query the DB correctly , maybe parsing the array is too fast for the query ??? I attached a results for a grading page thanks Jim -Original Message- From: FLAHERTY, JIM-CONT [mailto:[EMAIL PROTECTED]] Sent: Thursday, May 23, 2002 4:08 PM To: Beginners (E-mail) Subject: Hello all this grading program is still messing up I have a test maker script , that generates random questions from a DB My grader script needs to grade those same random questions it has a variable that called $questions_asked its output is like this !146!612!145!385!655!34!122!583!119!109 the code #! /usr/bin/perl #user grading script # # May 23, 2002 ver 0.03 require subparseform.lib; Parse_Form; $test = $formdata{'test12'}; $sname = $formdata{'name'}; $date1 = $formdata{'date1'}; $numofques = $formdata{'numofques'}; $questions_asked = $formdata{'admin_test'}; ### # make Page print content-type: text/html\n\n; print html\n; print head\n; print Script Language=\JavaScript\\n; print //--+\n; print // SmartMenus v.1 |\n; print // \©2001 VASIL DINKOV - PLOVDIV, BULGARIA |\n; print // http://mp3.dinkov.com http://mp3.dinkov.com | vasko\@dinkov.com |\n; print //--+\n; print // For Internet Explorer 4 and Netscape 6 |\n; print //--+\n\n; print //==1==Defining Colors\n; print var menuFrameColor=\'#4d4c76\'\;\n; print var menuBgColor=\'#bebddf\'\;\n; print var menuOverBgColor=\'#fff5c6\'\;\n; print var menuFontColor=\'#4d4c76\'\;\n; print var menuOverFontColor=\'#4d4c76\'//(can be the same as menuFontColor)\n\n ; print //==2==Defining TARGET for the links in the menu\n; print var target=\'self\'//(newWindow or self)(cannot navigate to frame)\n\n; print //==3==Defining font, menu cell padding frame border width\n; print var font=\'verdana,arial,helvetica\'\;; print var fontSize=\'10px\'\;\n; print var fontWeight=\'bold\'\;//(bold or normal)\n; print var cellPadding=\'2\'\;\n; print var frameBorderWidth=\'1\'\;\n; print //==4==Defining The Menus Width\n; print var menuWidth=\'140\'\;\n; print //==5==Defining The Menus Placement (top left corner of the menus)\n; print var menuTopPixels=15\;//from document top left corner(without quotes)\n ; print var menu1LeftPixels=0\;\n; print var menu2LeftPixels=74\;\n; print var menu3LeftPixels=144\;\n; print var menu4LeftPixels=226\;\n; print var menu5LeftPixels=296\;\n; print //var menu6LeftPixels=400\;//(if you want more add like this)\n; print //==6==Defining The Menus Count (how many do you want)\n; print var menuCount=2\;//(without quotes)\n; print //=MENU DEFINITIONS=\n; print //(be sure to have the same number of array items for both href text)\n; print //===Menu 1\n; print href1=new Array(\'nam.cgi\',\'addmaterial.cgi\',\'adduser.php\',; print \'\')\;\n; print text1=new Array(\'Add a Patron\',\'Add Material\',\'Add a User\',; print \'Edit a User\')\;\n; print function MV1(){var x=\'\'\;for(i=0\;ihref1.length\;i++); print {x=x+\trtd class=mxz onclick=doGo(\'\+href1[i]+\\'); print onmouseover=ov(this) onmouseout=ou(this)\+text1[i]+\/td; print /tr\}\;return x}\;\n; print //===Menu 1 END \n\n\n; print //===Menu 2\n; print href2=new Array(\'checkout_report.cgi\')\;\n; print text2=new Array(\'Checkout Report\')\;\n\n; print function MV2(){var x=\'\'\;for(i=0\;ihref2.length\;i++); print {x=x+\trtd class=mxz //onclick=doGo(\'\+href2[i]+\\'); print onmouseover=ov(this) onmouseout=ou(this)\+text2[i]+\/td; print /tr\}\;return x}\;\n; print //===Menu 2 END \n\n\n; print //=MENU DEFINITIONS END= \n; print // THE SERIOUS SCRIPT PLEASE DO NOT TOUCH\n; print if(document.all){topY=menuTopPixels}else{topY=menuTopPixels-2}\;; print /*NS bud*/function rV(){q=\'\'\;for(z=1\;z=menuCount\;z++); print {if(document.all){q=q+\m\+z+\.style.display=\'none\'\;\}; print else{q=q+\document.getElementById(\'m\+z+\\').style.display=\'none\'\;\ }}\;return q}\;; print eval(\function hide(a){if(a.clientY=topY){\+rV()+\}}\;; print function hide2(){\+rV()+\}\)\;eval(\function ov(ok); print {ok.style.background=\'\+menuOverBgColor+\\'\;ok.style.; print color=\'\+menuOverFontColor+\\'}\;function ou(ok); print {ok.style.background=\'\+menuBgColor+\\'\;ok.style.; print color=\'\+menuFontColor+\\'}\;function doGo(ok); print {var tgt=\'\+target+\\'\;if(tgt==\'newWindow\'){window.open(ok); print }else{document.location.href=ok}}\;function show
Perl / MySQL problem
Does anyone have an Idea whats going on here , I have an array feeding a SQL Query, But it doesnt always come back with a success . What this query does it is on a Quiz web site . Students take quiz, variable is passed to grade.cgi. that variable is parsed with a while statement. and a variable is feed to the query. If the student takes 10 question, only 6 or 7 will get graded. I have red hat 7.2 and mysql 3.23 , is it possible the while statement executes to fast for the query ?? Code: ## # connect to DB use DBI; my $database = cram; my $data_source = DBI:mysql:$database; my $username = user; my $password = password; $dbh =DBI -connect($data_source, $username, $password) or die cant connect to $data_source : my $dbh- errstr\n; while( $questions_asked =~ /!([^!]*)/g) { my $num1 = $1; print This is a test: $num1BR; # this statement for debug my $sth1 = $dbh - prepare(select * from tests where num = '$num1' ); $sth1 - execute or die unable to execute query ; #$sth1 - finish; my $array_ref = $sth1 - fetchall_arrayref(); It would miss every other to every third one Help! thanks Jim
How to a parse a string in perl
I want to slice up this variable into a single variable and loop until its empty The variable is seperated via ! explnation points and I want the numbers. This string can be various in length ? Note it doesnt end with that delimiter. Help example $jims = !23!45!67
Scripts picks random elements from array , but it repeats sometimes
Hello , My script picks out random elements from an array , but it sometimes repeats ( which is no good) .. I want to prevent this , Do I delete the element from the array or is there a better way ? And how do I do either ? Thanks Jim
FW: Scripts picks random elements from array , but it repeats sometimes
Hello , My script picks out random elements from an array , but it sometimes repeats ( which is no good) .. I want to prevent this , Do I delete the element from the array or is there a better way ? And how do I do either ? my mistake here is the code while($numofques 0) { $index = rand numbers; $element = $numbers[$index]; Thanks Jim
How do I pass an array to another CGI script
What is the best and easiest way to pass an array to another CGI script? I am open for any suggestion -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Help with MIME::Lite module
I am wanting to send HTML reports to clients that can read html mail. In the Data section is where you put the body of the message . If I type html tag and text it works fine. but when I try to add a variable the body of the message has $nhtmlpage nothing on whats in the variable. Help code my $msg = MIME::Lite-new( From = '[EMAIL PROTECTED]' mailto:'[EMAIL PROTECTED]' , To = '[EMAIL PROTECTED]' mailto:'[EMAIL PROTECTED]' , Cc = '[EMAIL PROTECTED]' mailto:'[EMAIL PROTECTED]' , Subject= 'Morning Trouble Call report', Type = 'text/html', Data = '$rhtmlpage' ); $msg-send();
I have numbers in an array how do extract them in a random order ?
I have numbers in an array how do extract them in a random order ? . I want to feed them to a sql query to extract information , just the first 10 of them code ## $dbh =DBI -connect($data_source, $username, $password) or die cant connect to $data_source : my $dbh- errstr\n; my $sth1 = $dbh - prepare(select num from tests where subject = '$test' ); $sth1 - execute or die unable to execute query ; #$sth1 - finish; $count1 = 0; my $array_ref = $sth1-fetchall_arrayref(); foreach $row($array_ref){ $num1 = $row-[0]; push(numbers, $num1); $count1++; } ### # now to extract them $num = rand(numbers) $dbh =DBI -connect($data_source, $username, $password) or die cant connect to $data_source : my $dbh- errstr\n; my $sth1 = $dbh - prepare(select * from tests where num = '$num1' ); $sth1 - execute or die unable to execute query ; Help Jim f
Trying to add things to an array , but it has blank spaces
Hello, It seams I am sucessfully adding numbers to my array , but in turn tey are blank spaces. I need Help My code $dbh =DBI -connect($data_source, $username, $password) or die cant connect to $data_source : my $dbh- errstr\n; my $sth1 = $dbh - prepare(select num from tests where subject = '$test' ); $sth1 - execute or die unable to execute query ; #$sth1 - finish; $count1 = 0; my $array_ref = $sth1-fetchall_arrayref(); foreach $row(@$array_ref){ $num = $row[0]; push(@numbers, $num); $count1++; } thanks You Jim -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
thanks for the response yesterday , but I still dont get it ... Trying not to add dup names in DB
I made the column testname unique . But I did quite understand how to change to query syntax. Stephen told me to add where clause Where IDENTIFIER NOT IN ( SELECT IDENTIFIER FROM TABLE) I dont get what he means .. I am new to perl . the table show columns from phistory; +---+-+--+-+-++ | Field | Type| Null | Key | Default | Extra | +---+-+--+-+-++ | num | int(4) | | PRI | NULL| auto_increment | | testname | varchar(60) | YES | MUL | NULL|| | numpeople | int(6) | YES | | NULL|| | numtimes | int(6) | YES | | NULL|| | average | float | YES | | NULL|| +---+-+--+-+-++ 5 rows in set (0.00 sec) mysql CODE my $sth1 = $dbh - prepare(select distinct testname from testhistory); $sth1 - execute or die unable to execute query ; #$sth1 - finish; my $array_ref1 = $sth1-fetchall_arrayref(); foreach $row($array_ref1) { my($tname) = $row; my $sth2 = $dbh - prepare(insert into phistory(testname)values('$tname')); $sth2 - execute or die unable to execute query ; #$sth1 - finish; } thanks Jim
Help ..trying to send HTML Email to clients on outlook 2k with MIME-Lite-HTML-1.8
I trying to send HTML Email to clients on outlook 2k with MIME-Lite-HTML-1.8 I want to send reports html enabled mail intead of the old text mail . I was working with this module from CPAN , help our am I going about it the wrong way Code #!/usr/bin/perl -w ### Get Date ### use strict; use CGI qw/:standard/; # use CGI::CARP qw/fatalsToBrowser/; use MIME::Lite::HTML; my $mailHTML = new MIME::Lite::HTML From = '[EMAIL PROTECTED]' mailto:'[EMAIL PROTECTED]' , To = '[EMAIL PROTECTED]' mailto:'[EMAIL PROTECTED]' , # To = param( '[EMAIL PROTECTED]' mailto:'[EMAIL PROTECTED]' ), Subject = 'Your html Mail'; url = http://www.cnn.com http://www.cnn.com ; my $MIMEmail = $mailHTML-parse(param('url')); $MIMEmail-send; ~ ~ errors Can't modify non-lvalue subroutine call in scalar assignment at test.cgi line 15 , near http://www.cnn.com http://www.cnn.com ; Execution of test.cgi aborted due to compilation errors.
I have a script that print test questions and grades them... how do I make them print a random order
I have a script that print test questions and grades them... how do I make them print a random order, and a certain amount ?? code $dbh =DBI -connect($data_source, $username, $password) or die cant connect to $data_source : my $dbh- errstr\n; my $sth1 = $dbh - prepare(select * from tests where subject = '$test' ); $sth1 - execute or die unable to execute query ; #$sth1 - finish; ## the table mysql show columns from tests; +-+--+--+-+-++ | Field | Type | Null | Key | Default | Extra | +-+--+--+-+-++ | num | int(5) | | PRI | NULL| auto_increment | | subject | varchar(200) | YES | | NULL|| | ques| longtext | YES | | NULL|| | quesA | longtext | YES | | NULL|| | quesB | longtext | YES | | NULL|| | quesC | longtext | YES | | NULL|| | quesD | longtext | YES | | NULL|| | quesE | longtext | YES | | NULL|| | ans | varchar(20) | YES | | NULL|| | corr_a | char(2) | YES | | NULL|| | corr_b | char(2) | YES | | NULL|| | corr_c | char(2) | YES | | NULL|| | corr_d | char(2) | YES | | NULL|| | corr_e | char(2) | YES | | NULL|| | exp | longtext | YES | | NULL|| | pipe| varchar(20) | YES | | NULL|| +-+--+--+-+-++ 16 rows in set (0.00 sec) mysql thanks Jim
How Do I add a record to a table if it dont exist ??
I have a delima I want to add records to a table in mysql , only if that record isnt there , Help Code my $sth1 = $dbh - prepare(select distinct testname from testhistory); $sth1 - execute or die unable to execute query ; #$sth1 - finish; my $array_ref1 = $sth1-fetchall_arrayref(); foreach $row($array_ref1) { my($tname) = $row; my $sth5 = $dbh- prepare(select testname from phistory); $sth5 - execute or die unable to execute query ; #$sth1 - finish; my $array_ref5 = $sth5-fetchall_arrayref(); foreach $row1($array_ref5) { my($tname) = $row1; if ($tname ne ){ my $sth2 = $dbh - prepare(insert into phistory(testname)values('$tname')); $sth2 - execute or die unable to execute query ; #$sth1 - finish; } } this code doesnt add at all Thanks Jim
I am clueless about making my test generator program to generate random questions.... Help
I have a script that generates test questions and grades them . I was asked to make them generate in a random order , can someone point me in the right direction They come in two files make_test.cgi and grade.cgi #! /usr/bin/perl # #make test for Cram Program # # version 0.02 mar 18 2002 # require subparseform.lib; Parse_Form; $name = $formdata{'name'}; $test = $formdata{'test1'}; ## # connect to DB use DBI; my $database = cram; my $data_source = DBI:mysql:$database; my $username = root; my $password = elaine; ## make sure they havent taken the test before # $dbh = DBI - connect($data_source, $username, $password) # my $sth = $dbh1 - prepare(select * from scores where name = '$name' and test = '$test'); # $sth - execute # $result = $result # if($result ne ) { # my Arrary ## ###Make Random # ## $dbh =DBI -connect($data_source, $username, $password) or die cant connect to $data_source : my $dbh- errstr\n; my $sth1 = $dbh - prepare(select * from tests where subject = '$test' ); $sth1 - execute or die unable to execute query ; #$sth1 - finish; ## # make count $count = 0; ### # make Page print content-type: text/html\n\n; print html\n; print headtitle Welcome ; print $name; print /title/head\n; print /head\n; print body bgcolor=\#FF\ text=\00\ \n; print background=\notebook.jpg\\n\n; print h3 align=\right\$name /h3 \n; print h3 align=\right\$test Test/h3 \n; print hr\n; print div align=\center\\n; print center\n; print table border=\1\ width=\80%\\n; print form action=\grade.cgi\; print method=\post\ ; print name=\cramtest\\n; print input type=\hidden\ name=\name\ value=\$name\\n; print input type=\hidden\ name=\test12\ value=\$test\\n; my $array_ref = $sth1 - fetchall_arrayref(); foreach $row($array_ref){ ## # Count Routine ## # $count ++; # my($num, $subject, $ques,$quesA, $quesB, $quesC, $quesD,$quesE,$ans) = $row; $tot_ans = 0; print tr\n; print td width=\3%\$num/td\n; print td width=\3%\nbsp;/td\n; print td width=\84%\ bgcolor=\#00\$ques\n; $c_ans = $num.c_ans; print nbsp; nbsp; input type=\hidden\ name=\$c_ans\ value=\$ans\\n; print /td\n; print /tr\n; $ques1a = $num.a; if ($quesA ne ){ $tot_ans++; print tr\n\n; print td width=\3%\nbsp;input type=\checkbox\ name=\$ques1a\\n; print value=\ON\/td\n\n; print td width=\3%\nbsp;A./td\n; print td width=\84%\$quesA /td\n; print /tr\n; } $ques1b = $num.b; if ($quesB ne ){ $tot_ans++; print tr\n; $num_a = $num; print td width=\3%\nbsp;input type=\checkbox\ name=\$ques1b\ ; print value=\ON\/td\n; print td width=\3%\nbsp;B./td\n; print td width=\84%\$quesB/td\n; print /tr\n; } $ques1c = $num.c; if ($quesC ne ){ $tot_ans++; print tr\n; print td width=\3%\nbsp;input type=\checkbox\ name=\$ques1c\ ; print value=\ON\/td\n; print td width=\3%\nbsp;C./td\n; print td width=\84%\$quesC/td\n; print /tr\n; } $ques1d = $num.d; if ($quesD ne ){ $tot_ans++; print tr\n; print td width=\3%\nbsp;input type=\checkbox\ name=\$ques1d\ ; print value=\ON\/td\n; print td width=\3%\nbsp;D./td\n; print td width=\84%\$quesD /td\n; print /tr\n; } if ($quesE ne ){ $tot_ans++; $ques1e = $num.e; print tr\n; print td width=\3%\nbsp;input type=\checkbox\ name=\$ques1e\ ; print value=\ON\/td\n; print td width=\3%\nbsp;E./td\n; print td width=\84%\$quesE /td\n; print /tr\n; } $ques1f = $num.f; if ($quesf ne ){ $tot_ans++; print tr\n; print td width=\3%\nbsp;input type=\checkbox\ name=\$ques1f\ ; print value=\ON\/td\n; print td width=\3%\nbsp;f./td\n; print td width=\84%\$quesf /td\n; print /tr\n; } $tot_ans1 = $num.tot_ans1; print input type=\hidden\ name=\$tot_ans1\ value=\$tot_ans\\n; } print input type=\hidden\ name=\count\ value=\$count\\n; print /table\n; print input type=\Submit\ value=\Submit to Be Graded\\n; print /form\n; print /center\n; print /div\n; print /body\n; print /html\n; #! /usr/bin/perl #user grading script # # Mar 18, 2002 ver 0.02 require subparseform.lib; Parse_Form; $test = $formdata{'test12'}; $sname = $formdata{'name'}; ## # connect to DB use DBI; my $database = cram; my
perl DBI to Mysql , what happens when field I query is blank ?
Hello I have redhat 7.1 and mysql , I am trying to query DB of People if there is no record for this person , I want to add them . My problem seams to be what is in query results with it comes back blank here is the code $dbh1 =DBI -connect($data_source, $username, $password) or die cant connect to $data_source : my $dbh- errstr\n; my $sth1 = $dbh1 - prepare(select owner from users where owner = '$user_n'); $sth1 - execute or die unable to execute query ; # $sth1 - finish; # $dbh1-disconnect; my $array_ref = $sth1 - fetchall_arrayref(); foreach $row($array_ref){ my($owner) = $row; if($owner eq NULL){ $dbh4 =DBI -connect($data_source, $username, $password) or die cant connect to $data_source : my $dbh- errstr\n; my $sth2 = $dbh4 - prepare(insert into users(owner)values('$user_n')); $sth2 - execute or die unable to execute query ; } } $sth - finish; # look up results ?? thanks in advance Jim
How do I get trim or rounding on a float number ?
$ aver = $total_hours/$total_jobs some times comes up with 24.97 . I would like to round or trim to 24.99 for example . any Ideas ?? thanks Jim F
Help with negitive query results in Perl and MySql
I have Red hat 7.1 . I have a script that scans the common drive and gathers file owner name , size, and last access date . and dumps into a DB. the second half if the script gets owners name and looks up in another table .. that I have been manually installing user name to email . I want the script if It cant find a email for the user , it will email to remind me to research the name and enter a email. The problem is quering the table and what is the result when It doesnt find an email for this users Here is the Code # # Open userfile and put into an array # # open(LOG,/var/www/html/bad/users.txt); @logmess = LOG; close(LOG); ## ### get dink users email address ### ## my $database = shared; my $data_source = DBI:mysql:$database; my $username = root; my $password = elaine; $dbh1 =DBI -connect($data_source, $username, $password) or die cant connect to $data_source : my $dbh- errstr\n; ## this is broke needs something that reads results NULL or none foreach $mess1(@logmess) { my $sth1 = $dbh1 - prepare(select email from users where owner = '$mess1'); $sth1 - execute or die unable to execute query ; my $array_ref = $sth1-fetchall_arrayref(); ## # add string to check if query came back negitive # # ( check other scripts ) # # print Name : $mess1\n; # # foreach $row(@$array_ref) { my ($email_u) = @$row; print $mess1 and $email_u\n; if ($email_u eq NULL){ print the is Bad: $mess1\n; open(LOG3,/var/www/html/bad/Badusers.txt); print LOG3 $mess1\n; close(LOG3); } if($email_u ne ){ # get files and email user open(MAIL, |/usr/lib/sendmail -t)|| ErrorMail; print MAIL To:$email_u\nFrom:jim.flaherty\@somewhere.com\n; print MAIL Subject:Unused files on shared drive\n\n\n; print MAIL The following listed files are Files you own on the Shared drive\n; print MAIL ( Drive s:) havent been accessed for 6 months. Please Click on \n; print MAIL the link below to review your files. ; print MAIL Please delete any unnessary files : ; print MAIL http://kins2158/bad/$mess1;; print MAIL \n\n If you have any questions please call Jim Flaherty at 3420; close(MAIL); } }
help with count query in mysql
How do you do a count query in mysql ? I have redhat 7.1 mysql 3.23 code ## # get stats ## use DBI; my $database = VHD; my $data_source = DBI:mysql:$database; my $username = name; my $password = password; $dbh =DBI -connect($data_source, $username, $password); my $sth1 = $dbh - prepare(select count(*) from jobs where status = 'closed'); $sth1 - execute or die unable to execute query ; my $array_ref = $sth1 - fetchall_arrayref(); foreach $row(@$array_ref){ my($closedJ) = @$row; # print LOG $row; print LOG $closedj[0]; } $dbh - disconnect; thank you in advance Jim F
help with DBD error
hello, I have redhat 7.1 and perl is loaded with mysql , I have several scripts with perl , DBI, DBD and mysql working fine , so If think I have everything set up properly But I get an error : DBD::mysql::st execute failed: Duplicate entry '204' for key 1 at /var/www/cgi-b in/sobt/chstatus2.cgi line 107. unable to execute query at /var/www/cgi-bin/sobt/chstatus2.cgi line 107. Issuing rollback() for database handle being DESTROY'd without explicit disconnect(). this is the section of code ( with line numbers) 97 $dbh2 =DBI -connect($data_source, $username, $password); 98my $sth2 = $dbh2 - prepare(select title from media1 where num ='$nu m'); 99 100$sth2 - execute or die unable to execute query ; 101 102 103 $dbh2 =DBI -connect($data_source, $username, $password); 104my $sth2 = $dbh2 - prepare(insert into history(num,title,date,user1 )values('$num','$date1','$date1','$name')); 105 106 107$sth2 - execute or die unable to execute query ; 108 109 110 Help Thanks Jim F -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Help with global match and replace
My script dumps file name into a mysql DB on redhat 7.1 linux . The problem I have is sometime windows files has a single quote ( ' ) in the name. I want to replace it with a space . I not strong on pattern matching in perl yet $thestring = this isn't a good file name; Help , thanks in advance Jim F -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
problem with redirect
This is what my error log says on my redhat 7.1 [Sun Sep 16 13:18:33 2001] [error] Undefined subroutine main::redirect called at /var/www/cgi-bin/sobt/add.cgi line 38. [Sun Sep 16 13:18:44 2001] [error] [client 192.168.1.8] Premature end of script here is my code: $dbh =DBI -connect($data_source, $username, $password); my $sth1 = $dbh - prepare(insert into media(serial,name,desc1)values('$serial' ,'$name','$desc1')); $sth1 - execute ; #$sth1 - finish; $dbh-disconnect; ### # re direct page back ### print redirect('sobt_admin.cgi'); thanks for your time Jim -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Issuing rollback() for database handle being DESTROY'd without explicit disconnect().
Why am I getting this ?? Issuing rollback() for database handle being DESTROY'd without explicit disconnect(). the code #!/usr/bin/perl # Script to maintain KBHD Stats # # Version 1.0 # # date : 6 Jun 01# # require subparseform.lib; # Parse_Form; ### # Start Writing the Page # ### open(LOG,/var/www/html/kbhd/stats.php); print LOG HTMLHEAD\n; print LOG Title Stats for Techs /title\n; print LOG /head\n; print LOG body bgcolor=\#C0C0C0\ text=\00\\n; print LOG div align=\center\\n; print LOG h1Stats Page/h1\n; print LOG /div\n; print LOG hr align=\center\ size=\4\ width=\80%\\n; # !-- this is the Stats Page , it will have reports total jobs and grades -- ## # get stats ## use DBI; my $database = VHD; my $data_source = DBI:mysql:$database; my $username = user; my $password = password; $dbh =DBI -connect($data_source, $username, $password); my $sth1 = $dbh - prepare(select count(*)from jobs where status = 'closed'); $sth1 - execute or die unable to execute query ; my $array_ref = $sth1 - fetchall_arrayref(); foreach $row(@$array_ref){ my($closedJ) = @$row; } print LOG pnbsp;nbsp;nbsp;nbsp;nbsp;nbsp;; print LOG font color=\#800080\bOverall Stats/b/font/p; print LOG div align=\center\\n; print LOG center\n; print LOG table border=\1\ width=\80%\\n; print LOG tr\n; print LOG td width=\38%\ bgcolor=\#FF\b; print LOG font color=\#FF\Number Ofnbsp; print LOG Closed Jobs :nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;; print LOG /fontfont color=\#00\\n; print LOG $closedJ /font/b/td\n; print LOG td width=\30%\Total Time/td\n; print LOG td width=\34%\Average time per Call/td\n; print LOG /tr \n; print LOG /table\n; print LOG brhr size=\4\\n; print LOG bGrades for techs /b\n; ### #Query techs names# ### use DBI; my $database = VHD; my $data_source = DBI:mysql:$database; my $username = ; my $password = ; $dbh =DBI -connect($data_source, $username, $password); my $sth1 = $dbh - prepare(select username from tech1); $sth1 - execute or die unable to execute query ; my $array_ref = $sth1 - fetchall_arrayref(); foreach $row(@$array_ref){ my($tech) =@$row mailto:=@$row ; print LOG center $tech /centerbr\n; print LOG table border=\1\ width=\40%\ bgcolor=\#00FF00\\n; print LOG TR\n; print LOG td width=\57%\bnbsp;nbsp; Total Jobs Completed/b/td\n; print LOG td width=\6%\nbsp;/td\n ; print LOG td width=\37%\nbsp;nbsp; bfont color=\#FF\ 53/font /b/td\n; print LOG /tr\n; print LOG tr \n; print LOG td width=\57%\nbsp;bnbsp; Total Hours Spentnbsp;nbsp; /b /td\n; print LOG td width=\6%\nbsp;/td\n; print LOG td width=\37%\nbsp;nbsp;nbsp; font color=\#FF\b56/b /font/td\n; print LOG /tr\n; print LOG tr\n; print LOG td width=\57%\nbsp;/td\n; print LOG td width=\6%\nbsp;/td\n; print LOG td width=\37%\nbsp;/td\n; print LOG /tr\n; print LOG tr\n; print LOG td width=\57%\nbsp;nbsp; font color=\#00\bAverage time to; print LOG Complete/b/font /td\n; print LOG td width=\6%\nbsp;/td\n; print LOG td width=\37%\nbsp;nbsp;nbsp; font color=\#FF\b67/b /font/td\n; print LOG /tr\n; print LOG /table\n; print LOG brbr\n; } close(LOG);
is there a receipt for send mail
Hello, I want to automatically get a receipt for a user when they read the email my script sends out . I have red hat 7.1 Thanks in advance Jim
Help With Matching
I am trying to substite , I want to replacebetween the words and replacing them with /tdtd because I am reading a file that is uploaded and making a table in a web page when this script is run $test1 = the is a test; $test1 = s///td/td/g I dont get the desired result , can anyone help ?