Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi, All I know that this should

Status
Not open for further replies.

aitai

MIS
Jul 3, 2001
36
US
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 qw:)standard);
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&quot;<br />\n&quot;;
print&quot;<center>\n&quot;;
print&quot;<h2>Course Description</h2>\n&quot;;
print&quot;</center>\n&quot;;
print&quot;<br />\n&quot;;
}

sub PrintPageEnd{
print &quot;</body>\n&quot;;
print &quot;</html>\n&quot;;
}

sub PrintCourses{

while (@row=$sth->fetchrow_array){
($Course_No,$Title,$Description,$Credits,$Prerequisite)=@row;
print &quot;<table>\n&quot;;
print &quot;<tr>\n<td><b>Course Number: </b></td>\n<td>$Course_No</td>\n</tr>\n&quot;;
print &quot;<tr>\n<td><b>Title: </b></td>\n<td>$Title</td>\n</tr>\n&quot;;
print &quot;<tr>\n<td><b>Description: </b></td>\n<td>$Description</td>\n</tr>\n&quot;;
print &quot;<tr>\n<td><b>Credits: </b></td>\n<td>$Credits</td>\n</tr>\n&quot;;
print &quot;<tr>\n<td><b>Prerequisites: </b></td>\n<td>$Prerequisite</td>\n</tr>\n&quot;;
print &quot;</table>\n&quot;;}
}

sub EmptyRecordset{
print &quot;<b>You did not make a valid select. Try again!</b>\n&quot;;
}
 
You need quotes around the value of $Course_no since it is alphanumeric.
$Statement = &quot;select * from courses where Course_no = '&quot; . $Course_no . &quot;'&quot;;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top