Hi, All
I know that this should be simple, and for some reason I am losing my hair! I would appreciate any insight into this problem. Thanks in advance.
This is the full error message:Can't execute the select statement:Unknown column 'INSS209' in 'where clause'
The unknown column in the message is a url parameter passed:
$cgi = new CGI;
$Course_No = $cgi->param('Course_No');
Course_No is the column name, and INSS209 is the value.
I am using ActiveStatePerl and MySQL on WIN2K.
The full script;
#!D:/perl/bin/perl
use CGI qwstandard);
use CGI::Carp qw(fatalsToBrowser);
use DBI;
$cgi = new CGI;
$Course_No = $cgi->param('Course_No');
#define variables
$database="test";
$host="localhost";
$user="avandermerwe";
$password="aitai";
if ($Course_No = $cgi->param('Course_No')){
&ConnectDB;
&PrintPageStart;
&CourseQuery;
&PrintCourses;
&ConnectEnd;
&PrintPageEnd;
}
else{
&PrintPageStart;
&EmptyRecordset;
&PrintPageEnd;
}
#connect to MySQL database
sub ConnectDB {
$dbh=DBI->connect ("DBI:mysql:$database:$host",$user,$password);
}
#end connection to MySQL database
sub ConnectEnd {
$rc=$sth->finish;
$rc=$dbh->disconnect;
}
#select courses from the database
sub CourseQuery{
#my $Course_No = $cgi->param('Course_No');
$Statement = qq[
SELECT *
FROM courses
WHERE Course_No = $Course_No
];
# prepare statement for execution
$sth = $dbh->prepare($Statement)
or die "Can't prepare the query:", $sth->errstr, "\n";
#execute the query
$rv=$sth->execute
or die "Can't execute the select statement:", $sth->errstr, "\n";
}
sub PrintPageStart{
# Prepare HTML headers
print header, start_html (-title=>"Course Description",-bgcolor=>'white');
print"<br />\n";
print"<center>\n";
print"<h2>Course Description</h2>\n";
print"</center>\n";
print"<br />\n";
}
sub PrintPageEnd{
print "</body>\n";
print "</html>\n";
}
sub PrintCourses{
while (@row=$sth->fetchrow_array){
($Course_No,$Title,$Description,$Credits,$Prerequisite)=@row;
print "<table>\n";
print "<tr>\n<td><b>Course Number: </b></td>\n<td>$Course_No</td>\n</tr>\n";
print "<tr>\n<td><b>Title: </b></td>\n<td>$Title</td>\n</tr>\n";
print "<tr>\n<td><b>Description: </b></td>\n<td>$Description</td>\n</tr>\n";
print "<tr>\n<td><b>Credits: </b></td>\n<td>$Credits</td>\n</tr>\n";
print "<tr>\n<td><b>Prerequisites: </b></td>\n<td>$Prerequisite</td>\n</tr>\n";
print "</table>\n";}
}
sub EmptyRecordset{
print "<b>You did not make a valid select. Try again!</b>\n";
}
I know that this should be simple, and for some reason I am losing my hair! I would appreciate any insight into this problem. Thanks in advance.
This is the full error message:Can't execute the select statement:Unknown column 'INSS209' in 'where clause'
The unknown column in the message is a url parameter passed:
$cgi = new CGI;
$Course_No = $cgi->param('Course_No');
Course_No is the column name, and INSS209 is the value.
I am using ActiveStatePerl and MySQL on WIN2K.
The full script;
#!D:/perl/bin/perl
use CGI qwstandard);
use CGI::Carp qw(fatalsToBrowser);
use DBI;
$cgi = new CGI;
$Course_No = $cgi->param('Course_No');
#define variables
$database="test";
$host="localhost";
$user="avandermerwe";
$password="aitai";
if ($Course_No = $cgi->param('Course_No')){
&ConnectDB;
&PrintPageStart;
&CourseQuery;
&PrintCourses;
&ConnectEnd;
&PrintPageEnd;
}
else{
&PrintPageStart;
&EmptyRecordset;
&PrintPageEnd;
}
#connect to MySQL database
sub ConnectDB {
$dbh=DBI->connect ("DBI:mysql:$database:$host",$user,$password);
}
#end connection to MySQL database
sub ConnectEnd {
$rc=$sth->finish;
$rc=$dbh->disconnect;
}
#select courses from the database
sub CourseQuery{
#my $Course_No = $cgi->param('Course_No');
$Statement = qq[
SELECT *
FROM courses
WHERE Course_No = $Course_No
];
# prepare statement for execution
$sth = $dbh->prepare($Statement)
or die "Can't prepare the query:", $sth->errstr, "\n";
#execute the query
$rv=$sth->execute
or die "Can't execute the select statement:", $sth->errstr, "\n";
}
sub PrintPageStart{
# Prepare HTML headers
print header, start_html (-title=>"Course Description",-bgcolor=>'white');
print"<br />\n";
print"<center>\n";
print"<h2>Course Description</h2>\n";
print"</center>\n";
print"<br />\n";
}
sub PrintPageEnd{
print "</body>\n";
print "</html>\n";
}
sub PrintCourses{
while (@row=$sth->fetchrow_array){
($Course_No,$Title,$Description,$Credits,$Prerequisite)=@row;
print "<table>\n";
print "<tr>\n<td><b>Course Number: </b></td>\n<td>$Course_No</td>\n</tr>\n";
print "<tr>\n<td><b>Title: </b></td>\n<td>$Title</td>\n</tr>\n";
print "<tr>\n<td><b>Description: </b></td>\n<td>$Description</td>\n</tr>\n";
print "<tr>\n<td><b>Credits: </b></td>\n<td>$Credits</td>\n</tr>\n";
print "<tr>\n<td><b>Prerequisites: </b></td>\n<td>$Prerequisite</td>\n</tr>\n";
print "</table>\n";}
}
sub EmptyRecordset{
print "<b>You did not make a valid select. Try again!</b>\n";
}