473,382 Members | 1,302 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Perl DBI: Getting POST info into select query

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.
Jul 19 '05 #1
1 5727
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.

Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: banz | last post by:
Hello I have a problem to resolve: I wrote a Perlscript which caches data from a server (local on my machine) I would like to have a other connection to a remote server but I don't know how to...
5
by: olaamussah | last post by:
Hi, i just started learning perl which i would use for my uni. project unfortunately. Well, this is a simple user login page i tried to create but i cant get it to work. Can someone please check this...
3
by: hakiran | last post by:
Hello all, I have been using Perl DBI the last 6months or so. I use it extensively with MySQL. But recently i tried to access Oracle DB with it and was having trouble. Any help would be...
0
by: nickyxu | last post by:
Hi all, I have a script about query record from MS Access database. This database contains a table named Lengths. The list of field names is Sample_ID, Taxon_ID, Lenght. Question is coming:...
0
by: Rebles | last post by:
I'm writing a PERL script to access and insert rows into a Microsoft SQL. i'm using MS SQL Server Management Studio Express (2005) to architect tables and queries. I've inserted two records into...
1
by: Rebles | last post by:
Hi, I just posted this in the MS SQL Section, but maybe my problem is rooted in Perl, so it's more appropriate to post here instead (sorry for the double post) I'm writing a PERL script to...
82
by: happyse27 | last post by:
Hi All, I modified the user registration script, but not sure how to make it check for each variable in terms of preventing junk registration and invalid characters? Two codes below : a)...
2
by: smithji | last post by:
Hi All, I'm having a problem executing a MySQL query witihin Perl and was hoping that someone will be able to help me in my moment of stress. When I run the below script I get this...
3
by: pramod1984 | last post by:
#!/usr/bin/perl # PERL MODULES WE WILL BE USING use DBI; use DBD::mysql; use Asterisk::AGI; $AGI = new Asterisk::AGI; # HTTP HEADER
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.