Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl DBI: Getting POST info into select query

Reply
Thread Tools

Perl DBI: Getting POST info into select query

 
 
Mavis
Guest
Posts: n/a
 
      10-03-2004
Hi,

I'm trying to use a simple form to select by which column I will display
output from a MySQL database.

I'd like to display based on ORDER BY and select Written, Average, etc.

I know the data is getting to the script from the post, I just can't get it
to the select statement.

Here is the code:




#!/usr/bin/perl

use DBI;

$sizeOfFormInformation = $ENV{'CONTENT_LENGTH'};
read (STDIN, $form_info, $sizeOfFormInformation);

($field_name, $command) = split (/=/, $form_info);

my $dbh = DBI->connect ('DBI:mysql:eln8220s02', root) or die "Couldn't
connect to database: " . DBI->errstr;

my $sth = $dbh->prepare('

select marks.Last_Name, min(marks.Score) as Minimum, max(marks.Score) as
Maximum, avg(marks.Score) as Average, count(marks.Score) as Count from marks
where marks.Type = "quiz" and marks.Score > 0 group by Last_Name order by
[THIS IS WHERE I WANT TO INSERT THE POST DATA] desc

') or die "Couldn't prepare statement: " . $dbh->errstr;

$sth->execute;






Any help would be appreciated.

Thanks.


 
Reply With Quote
 
 
 
 
Andres Monroy-Hernandez
Guest
Posts: n/a
 
      10-03-2004
Why don't you use the CGI module to read the POST request?
Let's say you have a field in your POST request called 'order_by', you
would do:

use CGI;
my $query = CGI->new;
my $order_by = $query->param('order_by');

Check: http://www.perldoc.com/perl5.6/lib/CGI.html

Regards,

-Andrés

Mavis wrote:

> Hi,
>
> I'm trying to use a simple form to select by which column I will display
> output from a MySQL database.
>
> I'd like to display based on ORDER BY and select Written, Average, etc.
>
> I know the data is getting to the script from the post, I just can't get it
> to the select statement.
>
> Here is the code:
>
>
>
>
> #!/usr/bin/perl
>
> use DBI;
>
> $sizeOfFormInformation = $ENV{'CONTENT_LENGTH'};
> read (STDIN, $form_info, $sizeOfFormInformation);
>
> ($field_name, $command) = split (/=/, $form_info);
>
> my $dbh = DBI->connect ('DBI:mysql:eln8220s02', root) or die "Couldn't
> connect to database: " . DBI->errstr;
>
> my $sth = $dbh->prepare('
>
> select marks.Last_Name, min(marks.Score) as Minimum, max(marks.Score) as
> Maximum, avg(marks.Score) as Average, count(marks.Score) as Count from marks
> where marks.Type = "quiz" and marks.Score > 0 group by Last_Name order by
> [THIS IS WHERE I WANT TO INSERT THE POST DATA] desc
>
> ') or die "Couldn't prepare statement: " . $dbh->errstr;
>
> $sth->execute;
>
>
>
>
>
>
> Any help would be appreciated.
>
> Thanks.
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
getting query info in a url Jeff ASP .Net 4 02-27-2007 04:48 PM
select of select box will select multiple in another box palmiere Javascript 1 02-09-2004 01:11 PM
How to use select (select(2)) in Perl? Kenny McCormack Perl Misc 49 02-06-2004 05:06 PM
Post post post. Shel-hed Computer Support 2 11-08-2003 07:41 AM
Merging Excel Info into existing Access Database Query powerrun ASP General 5 10-23-2003 09:19 PM



Advertisments