I'm a newbie to both CGI and Perl, but I have tried to make a little script with Perl that connects to a mysql database.
It works fine from a konsol, but when I try on the net with som CGI I get a 500 error, I probaly made som big mistakes but Im stuck here.
My script looks like this
#!c:/perl/bin/perl.exe
use strict;
use CGI ':standard';
use DBI;
my $DataBaseName = "dbname";
my $DataBaseHost = "host";
my $DataBaseUser = "user";
my $DataBasePass = "pass";
my $DataHandle = DBI->connect("DBI:mysql:database=$DataBaseName;host=$DataBaseHost",
"$DataBaseUser",
"$DataBasePass",
{ RaiseError => 1,
AutoCommit => 0 }) ¦¦ die "Unable to connect to $DataBaseHost because $DBI::errstr";
$DataHandle->do("CREATE TABLE bookmark (id INTEGER(5) NOT NULL auto_increment,
title VARCHAR(40) default NULL,
link VARCHAR(40) default NULL,
decrip VARCHAR(40) default NULL,
KEY id (id)
)");
my $title = param('title');
my $link = param('link');
my $descrip = param('descrip');
$DataHandle->do("INSERT INTO bookmark values(id,'$title','$link','$descrip')");
$DataHandle->disconnect();
-------------------------------------------------
and the HTML
<form name="bookmark" method="post" action="../cgi-bin/index.pl">
<p>
Titel :
<input type="text" name="title">
</p>
<p>
Link :
<input type="text" name="link">
</p>
<p>Beskrivelse:<br>
<textarea name="descrip"></textarea>
</p>
<p>
<input type="reset" name="Reset" value="Reset">
<input type="submit" name="Submit" value="tilføj">
</p>
</form>
I hope someone could point me in the right direction again, thanks.
[edited by: jatar_k at 4:00 pm (utc) on Aug. 14, 2005]
[edit reason] generalized connection info [/edit]
If I replace the param() function and just replace it with normal words, and then run my script in a console, it works fine, it creates the tabel and put the values in the table.
But I want it to work with a simple html form so when i add something it the forms it will add it to the database.
I hope you understand.
$query = new CGI;
$value = $query->param('foo');
Look here:
[search.cpan.org...]
I'm not familiar with module syntax but don't you need to use something like:$query = new CGI;
$value = $query->param('foo');
that's only if you are using the OO method. If you are using the "standard" method:
use CGI qw':standard';
then you don't have to create a new object and you can just use the function style syntax:
use CGI qw/:standard/;
print header(),start_html();
my $string = param('foo');
print $string;
print end_html();
it's all in the CGI documentation.