perleager has asked for the wisdom of the Perl Monks concerning the following question:
$time = time; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($tim +e); $mon++; $year += 1900; $memo = "Original Message\n------------\n$INPUT{'memo'}"; $memo_final = $memo . "\n\nCreated by: $username\nDate Created: $year- +$mon-$mday\n\n"; use DBI; my $dbh_m = DBI->connect('DBI:mysql:MEMO') or print "Couldn't con +nect to database: " . DBI->errstr; $sql_m = " INSERT INTO memo VALUES ( '?', '$year-$mon-$mday', '$INPUT{'user'}', '$INPUT{'ref'}', '$INPUT{'username'}', 'notread', '$memo_final' ) "; $sth_m = $dbh_m->prepare($sql_m) or print "preparing: ",$dbh_m->errst +r; $sth_m->execute or print "executing: ", $dbh_m->errstr; $sth_m->finish; $dbh_m->disconnect; &header; print <<EOF; <B>Memo to $INPUT{'user'} successfully added.</b> <br> EOF &footer;
Now this code doesn't work and I'm not sure why. Am I using placeholders correctly?$time = time; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($tim +e); $mon++; $year += 1900; my $memo = "Original Message\n------------\n$INPUT{'memo'}"; my $memo_final = "$memo" . "\n\nCreated by: $username\nDate Created: $ +year-$mon-$mday\n\n"; use DBI; my $dbh_m = DBI->connect('DBI:mysql:MEMO') or print "Couldn't con +nect to database: " . DBI->errstr; DBI->trace(2); my $sth_m = $dbh_m->prepare(<<SQL); INSERT INTO memo (id, date, user, ref, creator, status, memo_text) val +ues (?, ?, ?, ?, ?, ?, ?) SQL $sth_m->execute('?', '$year-$mon-$mday', '$INPUT{'user'}', 'INPUT{'ref +'}', '$INPUT{'username'}', 'notread', '$memo_final'); #line 148 $sth_m->finish; $dbh_m->disconnect; DBI->trace(0); &header; print <<EOF; <B>Memo to $INPUT{'user'} successfully added.</b> <br> EOF &footer;
update (broquaint): title change (was Placeholders!)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using SQL Placeholders correctly
by grinder (Bishop) on Dec 21, 2003 at 22:21 UTC | |
|
Re: Using SQL Placeholders correctly
by jZed (Prior) on Dec 21, 2003 at 21:47 UTC | |
|
Re: Using SQL Placeholders correctly
by liz (Monsignor) on Dec 21, 2003 at 21:39 UTC | |
by pg (Canon) on Dec 21, 2003 at 23:29 UTC | |
|
Placeholder confusion .. and other items
by talexb (Chancellor) on Dec 22, 2003 at 04:28 UTC | |
|
Re: Using SQL Placeholders correctly
by cLive ;-) (Prior) on Dec 22, 2003 at 03:40 UTC | |
|
Re: Using SQL Placeholders correctly
by Anonymous Monk on Dec 22, 2003 at 07:34 UTC |