The one followup explaining the need for the correct
header output using CGI is correct, but the code example
you posted has some errors as well.
#!/usr/local/bin/perl
use CGI;
use DBI;
my $dbh;
$dbh = DBI->Connect("DBI:mysql:strossus:localhost","strossus",
"********");
my $table = $dbh->prepare qq'
CREATE TABLE players
(realname CHAR(20),
=
gold CHAR(40))');
$dbh->disconnect();
First thing is the connect method in DBI it is lower case
you are using Connect which is not valid.
The DSN is incorrect see code below for correct syntax.
The use of a ' as a delimiter an SQL statement is
dangerous since ' is a common character in SQL. I prefer ~
in my code or !
There also seems to be a missing ( at the start of the
prepare statement.
The prepared statement is never executed. You need to call
$table->execute if you want it to take action.
I would rewrite this block as
#!/usr/local/bin/perl
use strict;
use CGI qw/:standard/;
my $cgi = CGI->new();
print $cgi->header;
use DBI;
my $dbh;
$dbh = DBI->connect('DBI:mysql:strossus@localhost',
"strossus","********",
{ RaiseError => 1 });
my $table = $dbh->prepare(qq~
CREATE TABLE players (
realname CHAR(20),
gold CHAR(40)
)~
);
$table->execute();
$dbh->disconnect();
Warning I did minimal testing on this code :^) and I
didn't get into table design like one of the other
responders did. Proper table design is very important and
beyond the scope of this reply.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.