Front page | perl.beginners |
Postings from January 2002
pop-up box JOIN() to mysql not populating dates
Thread Next
From:
Keith A. Calaman
Date:
January 31, 2002 13:24
Subject:
pop-up box JOIN() to mysql not populating dates
Message ID:
ACEHJLEFEBHOIDOEECLCAEBICGAA.keith@kcalaman.com
I have pasted my code below. The problem I am having is:
my $ndate = join('-', $nyear,$nmonth,$nday);
is printing back to my form the exact format that should be correct to
insert into mysql. However, when the INSERT runs the value does not get
inserted properly. $nyear,$nmonth,$nday are grabbed from values a user
selects via three pop-up select boxes. Anyone have any ideas? Also, I am
new to this so your comments on my code are welcomed and appreciated.
Thanks in advance.
#!/usr/bin/perl -w
use strict;
use diagnostics;
print "Content-Type: text/html\n\n";
use CGI;
use DBI;
#declare form variables
my $query = CGI->new();
my $ntitle = $query->param('ntitle');
my $nyear = $query->param('year');
my $nmonth = $query->param('month');
my $nday = $query->param('day');
my $nurl = $query->param('nurl');
my $nblurb = $query->param('nblurb');
my $nsource = $query->param('nsource');
my $tracker = $query->param('tracker');
my $hostname = 'www.host.com';
my $database = 'sd';
my $user = 'usr';
my $password = 'guess';
my $driver = 'mysql';
#convert form variables
my $ndate = join('-', $nyear,$nmonth,$nday);
#connect to database
my $dsn = "DBI:$driver:database=$database;host=$hostname";
my $dbh = DBI->connect($dsn, $user, $password) or die "Cant connect to
the DB:
$DBI::errstr\n";
#determine what to do
if ($tracker eq 0){
print <<EndOfHTML;
<html>
<body>
<FORM METHOD=POST ACTION=" ">
<INPUT TYPE="hidden" NAME="tracktype" VALUE="2">
<INPUT TYPE="hidden" NAME="tracker" VALUE="1">
<INPUT TYPE="hidden" NAME="ntitle" VALUE="$ntitle">
<INPUT TYPE="hidden" NAME="ndate" VALUE="$ndate">
<INPUT TYPE="hidden" NAME="nurl" VALUE="$nurl">
<INPUT TYPE="hidden" NAME="nblurb" VALUE="$nblurb">
<INPUT TYPE="hidden" NAME="nsource" VALUE="$nsource">
Title: $ntitle<br>
Date: $ndate<br>
URL: $nurl<br>
Blurb: $nblurb<br>
Source: $nsource<br>
<P><INPUT TYPE=submit>
</body>
</html>
EndOfHTML
}elsif($tracker eq 1){
my $sth = $dbh->prepare("INSERT INTO News
(ntitle, ndate, nurl, nblurb, nsource)
VALUES('$ntitle', '$ndate', '$nurl', '$nblurb', '$nsource')");
$sth->execute();
my $new = $dbh->prepare("select N_ID, NDate, NSource, NTitle, NBlurb, NURL
from News WHERE NApprove=0");
$new->execute();
my $news;
while (my @row = $new->fetchrow_array()) {
$news .= qq| <value="$row[0]"> $row[1] <i>$row[2]</i><br>
<a href="$row[5]"><b>"$row[3]"</b></a><br>$row[4]..<br><br>\n|;
}
print <<EndOfHTML;
<html>
<body>
$news
</body>
</html>
EndOfHTML
}elsif($tracker eq 2){
print("there!\n");
}else{
print("failure!\n");
}
$dbh->disconnect;
exit;
Thread Next