On Sunday June 24 2007 6:39 pm, [EMAIL PROTECTED] wrote:
> This is rather long, but I just posted my old perl script, mysql
> table, and my new html form of which I'm trying to pass the values
> into the mysql table.  I'm digging into mysql now as I was previously
> using a program to pass form values to a .csv spreadsheet, but it was
> suggested that using mysql was going to be more helpful/powerful in
> the long run. So I have a database set up and know some general mysql
> commands. I've pasted the database below. With my previous script, I
> would just use the push function to fill an array and pass it into a
> spreadsheet row each time the user submitted. Now, I'd like to pass
> the form values into the mysql database.  As you can see, I've added
> some params since I used the previous perl script that sent the data
> to the .csv file.
>
> I purchased the book mysql and perl for the web, but it's a bit
> confusing b/c he creates the forms through perl instead of html (guess
> it's more streamlined). Is there something that I should be focusing
> on in his book with regards to inputting multiple form inputs (text,
> pull-down menu, etc) into mysql? It seems the big sticking point is
> putting the values into the right column of the database whereas
> before I was just pushing all values into a spreadsheet. Do I use the
> INSERT INTO statement and if so, how's a good way to use it?
> I'm sure I need to dig into knowing mysql more, but I'd just like to
> do simple stuff initially, like place the form data into the database
> instead of my previous excel spreadsheet. I believe if I get the basic
> of inserting the form submission data into the appropriate mysql
> columns, it will open many doors.  Thanks for any help!!!
>
> #!/perl/bin/perl -w
> use CGI qw(:standard);
> use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
> use strict;
>
> print header;
> print start_html("Regime");
>
> open(OUT, ">>C:/perl-scripts/Data/coldseasonworksheet.csv")
> or &dienice("couldn't open output file: $!");
>
> my @fields = qw(RI ET AT CUT FLT MIT GDP SOIA GSTOP HOLDING NONE ON
> OFF BAL TAF);
> my @output = ();
> push @output, param($_) || '""' for @fields;
>
> foreach my $i (@output) {
> print OUT "$i,";
> }
>
> print OUT "\n";
> close (OUT);
>
> print <<EndHTML;
> <h2>Thank You</h2>
> <Thank you for writing!!</p>
> EndHTML
>
> print end_html;
>
> sub dienice {
> my($errmsg) = @_;
> print "<h2>Error</h2>\n";
> print "<p>$errmsg</p>\n";
> print end_html;
> exit;
> }
>
> +----------------
> +---------------------------------------------------------------------
> +------+-----+---------+-------+
>
> | Field | Type | Null | Key | Default | Extra |
>
> +----------------
> +---------------------------------------------------------------------
> +------+-----+---------+-------+
>
> | Day | date | NO | PRI | | |
> |
> | SynRegime | enum('RI','ET','AT','CUT','FLT') | NO | | | |
> |
> | Impacts | set('MIT','GDP','SOIA','GSTOP','HOLDING','NONE') | NO | |
> |
> |
> | TAF | char(50) | NO | | | |
> |
> | Gradient | enum('ON','OFF','BAL') | NO | | | |
> |
> | Front | enum('WFRNT','ACFRNT','DCFRNT','NOFRNT') | NO | | | |
> |
> | UAL | char(50) | NO | | | |
> |
> | CWSU | char(50) | NO | | | |
> |
> | CritCldHgt |
>
> enum('LT21','2135','GT35','SHFTLT2100','SHFT2135','SHFTGT35') | NO | |
>
> | CritSFOWndFcst |
>
> enum('SEPLAN','WETSEPLAN','WPLAN','NPLAN','SHFTWPLAN','SHFTSEPLAN') |
> NO | | | |
>
> | CritSJCWndFcst |
>
> enum('SJCSEPLAN','SJCWPLAN','SHFTSJCSEPLAN','SHFTSJCWPLAN') | NO | | |
>
> | RwyFcst | enum('WET','DRY','SHFTWET','SHFTDRY') | NO | | | |
> |
> | LOCLDTIME | char(4) | NO | | | |
> |
> | SFOWNDTIME | char(4) | NO | | | |
> |
> | SJCWNDTIME | char(4) | NO | | | |
> |
> | RWYCONDTIME | char(4) | NO | | | |
> |
> | FROPA | char(4) | NO | | | |
> |
> | IT | char(4) | NO | | | |
> |
> | VT1 | char(4) | NO | | | |
> |
> | VT2 | char(4) | NO | | | |
> |
> | CANX | char(4) | NO | | | |
> |
> | IT2 | char(4) | NO | | | |
> |
> | VT12 | char(4) | NO | | | |
> |
> | VT22 | char(4) | NO | | | |
> |
> | CANX2 | char(4) | NO | | | |
>
> +----------------
> +---------------------------------------------------------------------
> +------+-----+---------+-------+
> 25 rows in set (0.02 sec)
>
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
> <html>
> <head>
> <title>Cold-Season Worksheet</title>
> <meta content="thumbnail view" name="description">
> <meta content="keene" name="author">
> </head>
> <body bgproperties="fixed" >
> <SCRIPT LANGUAGE="javascript">
> <!--
> document.write("<P ALIGN=right><l>" + Date()+"<\/l><\/P>")
> // -->
> </SCRIPT>
>
> <H2 ALIGN=Center>Cold-Season Worksheet Form</H2>
>
> <form action="http://localhost/cgi-bin/coldseasonworksheet.cgi";
> method="POST">
>
>
> <table width=400 align=center style="text-align: center;"
> target="_blank" border="1"
> cellpadding="2" cellspacing="2">
> <tbody>
> <tr>
> <Caption><B>Regime</B></Caption>
> <td style="vertical-align: top; text-align: center;">
> <select name="SynRegime">
> <option value="RI">Ridge
> <option value="ET">Exiting Trough
> <option value="AT">Approaching Trough
> <option value="CUT">Cutoff Low
> <option value="FLT">Flat<br>
> </td>
> </tr>
> </table>
>
>
> <table width=400 align=center style="text-align: center;"
> target="_blank" border="1"
> cellpadding="2" cellspacing="2">
> <tbody>
> <tr>
> <Caption><B>Front</B></Caption>
> <td style="vertical-align: top; text-align: center;">
> <select name="Front">
> <option value="WFRNT">Warm Front
> <option value="ACFRNT">Approaching Cold Front
> <option value="DCFRNT">Departing Cold Front<br>
> <option value="NOFRNT">No Front<br>
> </td>
> </tr>
> <tr>
> <td style="vertical-align: top; text-align: center;">
> Frontal Passage for SFO(ddtttt in day/zulu): <input type="text"
> name="FROPA"><br>
> </td>
> </tr>
> </body>
> </table>
> <br>
>
>
>
> <table width=400 align=center style="text-align: left;"
> target="_blank" border="1"
> cellpadding="2" cellspacing="2">
> <tr>
> <Caption><B>Gradient</B></Caption>
> <td style="vertical-align: top; text-align: center;">
> <select name="Gradient">
> <option value="ON">Onshore
> <option value="OFF">Offshore
> <option value="BAL">Balanced<br>
> </td>
> </tr>
> </table>
> <br>
>
>
>
> <table width=400 align=center style="text-align: left;"
> target="_blank" border="1"
> cellpadding="2" cellspacing="2">
> <tr>
> <Caption><B>TMU Update (AM:14Z PDT/15Z PST or PM:22Z PDT/23Z PST)</B></
> Caption>
> <td style="vertical-align: top; text-align: center;">
> TAF:<input type="text" name="TAF" size=50><br>
> UAL:<input type="text" name="UAL" size=50><br>
> CWSU:<input type="text" name="CWSU" size=50><br>
> </td>
> </tr>
> </table>
> <br>
>
> <table width=400 align=center style="text-align: left;"
> target="_blank" border="1"
> cellpadding="2" cellspacing="2">
> <tr>
> <Caption><B>Critical Cloud Height Forecast (CIG=SCT-BKN at SMB)</
> Caption></B>
> <td style="vertical-align: center; text-align: center;">
> <select name="CritCldHgt">
> <option value="LT21">Cig <2100ft (30-rate)</option>
> <option value="2135">Cig 2100ft-3500ft (SOIA)</option>
> <option value="GT35">Cig >3500ft (45/60-rate)</option>
> <option value="SHFTLT2100">All Shift <2100ft (30-rate)</option>
> <option value="SHFT2135">All Shift 2100ft-3500ft (SOIA)</option>
> <option value="SHFTGT35">All Shift >3500ft (45/60-rate)</option>
> </td>
> <td style="vertical-align: center; text-align: center;">
> Condition Forecast to Occur: <input type="text" name="LOCLDTIME"
> size=4>Z<br>
> </td>
> </tr>
> </table>
> <br>
>
> <table width=800 align=center style="text-align: center;"
> target="_blank" border="1"
> cellpadding="2" cellspacing="2">
> <tr>
> <td style="vertical-align: top; text-align: top;">SFO Winds<br>
> </td>
> <td style="vertical-align: top; text-align: top;">SFO Winds<br>
> </td>
> <td style="vertical-align: top; text-align: top;">SJC Winds<br>
> </td>
> <td style="vertical-align: top; text-align: top;">SJC Winds<br>
> </td>
> </tr>
> <tr>
> <Caption><B>Critical Wind Forecast (SFO and SJC)</B></Caption>
> <td style="vertical-align: top; text-align: top;">
> <select name="CritSFOWndFcst">
> <option value="SEPLAN">SE Winds 10KT+</option>
> <option value="WETSEPLAN">SE Winds 3KT-10KT</option>
> <option value="WPLAN">SW-NW Winds</option>
> <option value="NPLAN">NE Winds</option>
> <option value="SHFTWPLAN">All Shift SW-NW Winds</option>
> <option value="SHFTSEPLAN">All Shift SE Winds +10kt</option>
> </td>
> <td style="vertical-align: center; text-align: center;">
> Condition Forecast to Occur: <input type="text" name="SFOWNDTIME"
> size=4>Z<br>
> </td>
> <td style="vertical-align: top; text-align: top;">
> <select name="CritSJCWndFcst">
> <option value="SJCSEPLAN">SE Winds 6KT+</option>
> <option value="SJCWPLAN">SE Winds <6KT or Any Other Dir</option>
> <option value="SHFTSJCSEPLAN">All Shift SE Winds 6KT+</option>
> <option value="SHFTSJCWPLAN">All Shift SE Winds <6KT or Any Other Dir</
> option>
> </td>
> </td>
> <td style="vertical-align: center; text-align: center;">
> Condition Forecast to Occur: <input type="text" name="SJCWNDTIME"
> size=4>Z<br>
> </td>
> </tr>
>
> </table>
> <br>
>
> <table width=400 align=center style="text-align: left;"
> target="_blank" border="1"
> cellpadding="2" cellspacing="2">
> <tr>
> <B><text-align: center>Wet Runway<B>
> <td style="vertical-align: top; text-align: top;">
> <select name="RwyFcst">
> <option value="WET">Wet RWY at SFO</option>
> <option value="DRY">Dry RWY at SFO</option>
> <option value="SHFTWET">All Shift Wet RWY</option>
> <option value="SHFTDRY">All Shift Dry RWY</option>
> </td>
> <td style="vertical-align: center; text-align: center;">
> Condition Forecast to Occur: <input type="text" name="RWYCONDTIME"
> size=4>Z<br>
> </td>
> </tr>
>
> </table>
> <br>
>
> <table width=400 align=center style="text-align: left;"
> target="_blank" border="1"
> cellpadding="2" cellspacing="2">
> <tr>
> <B> <align=center>Impact to Operations</B>
> <td style="vertical-align: top; text-align: center;">
> <input type="checkbox" name="GS" value="GS">Ground Stop<br>
> </td>
> <td style="vertical-align: top; text-align: center;">
> <input type="checkbox" name="GDP" value="GDP">Ground Delay Program<br>
> </td>
> <td style="vertical-align: top; text-align: center;">
> <input type="checkbox" name="SOIA" value="SOIA">SOIA<br>
> </td>
> <td style="vertical-align: top; text-align: center;">
> <input type="checkbox" name="MIT" value="MIT">Miles in Trail<br>
> </td>
> <td style="vertical-align: top; text-align: center;">
> <input type="checkbox" name="NIMP" value="NIMP">No Impacts<br>
> </td>
> </table>
>
> <table width=400 align=center style="text-align: left;"
> target="_blank" border="1"
> cellpadding="2" cellspacing="2">
> <tr>
> <B> <align=center>GDP Data</B>
> <td style="vertical-align: top; text-align: center;">
> Issue Time(Z):<input type="text" size=4 maxlength=4 name="IT"><br>
> </td>
> <td style="vertical-align: top; text-align: center;">
> Valid Time(Z):<input type="text" size=4 maxlength=4 name="VT1">-<input
> type="text" size=4 maxlength=4 name="VT2"><br>
> </td>
> <td style="vertical-align: top; text-align: center;">
> Cancel Time(Z)<input type="text" size=4 maxlength=4 name="CANX"><br>
> </td>
> </table>
>
> <table width=400 align=center style="text-align: left;"
> target="_blank" border="1"
> cellpadding="2" cellspacing="2">
> <tr>
> <B> <align=center>Additional GDP Data</B>
> <td style="vertical-align: top; text-align: center;">
> Issue Time(Z):<input type="text" size=4 maxlength=4 name="IT2"><br>
> </td>
> <td style="vertical-align: top; text-align: center;">
> Valid Time(Z):<input type="text" size=4 maxlength=4 name="VT12">-
> <input type="text" size=4 maxlength=4 name="VT22"><br>
> </td>
> <td style="vertical-align: top; text-align: center;">
> Cancel Time(Z)<input type="text" size=4 maxlength=4 name="CANX2"><br>
> </td>
> </table>
>
> <table width=400 align=center style="text-align: left;"
> target="_blank" border="1"
> cellpadding="2" cellspacing="2">
> <tr>
> <B> <align=center>Overall Subjective Performance</B>
> <td style="vertical-align: top; text-align: center;">
> <select name="SubjPerform">
> <option value="GDAY">Good Day</option>
> <option value="BDAY">Bad Day</option>
> <option value="NOCHLLG">No Challenge</option>
> </td>
> </tr>
> </table>
> <br>
>
> <table width=400 align=center style="text-align: left;"
> target="_blank" border="1"
> cellpadding="2" cellspacing="2">
> <tr>
> <B> <align=center>Shift Notes</B>
> <td style="vertical-align: top; text-align: center;">
> <textarea name=SHFTNOTES rows=4 cols=40>
> </textarea>
> </td>
> </tr>
> </table>
>
> <input type="submit">
> <br>
> <br>
> <br>
> <input type="reset">
> </form>


use the DBI.pm and the mysql drivers .
get them from CPAN if you server doesnn't have them already. If they have Perl 
and Mysql then most likely the have them installed  already.

collect your passed params with the CGI.pm module , then  just  do an insert 
using the DBI.pm's  "do"  method.

The way your approaching it now is  ways harder.

short example:

use strict;
use CGI;
use DBI;

my $DATABASE ="something";
my $USERNAME = "Spongbob";
my $PASSWORD ="Squarepants";
my $HOSTNAME = "server.somplace.com ;
my $data_Source = "DBI:mysql:".$DATABASE .":".$HOSTNAME;

# create a  CGI object;
my $q = new CGI;


# collect passed values

my $SubjPerform = $q->param("SubjPerform");  
my $somthing2 = $q->param("anotherPassedValue");
my $somthing3 = $q->parqam("Still another passed value");


# create a DB object
my $dbh = DBI->connect($data_Source,$USERNAME,$PASSWORD) or  die 
"$DBI::errstr";


my $query = "insert into  tablename 
(atablenaem1,atablename2,atablename3)VALUES($SubjPerform,$somthing2,
$somthing3);


# insert  stuff in the db

$dbh->do($query) or die "$DBI::errstr";


very short , example but should get you going. Study the docs for these 
modules , they are full of examples. 

Good Luck

Greg Jetter
Alaska Internet Solutions


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to