Gossamer Forum
Home : General : Perl Programming :

HELP WITH CODE

Quote Reply
HELP WITH CODE
ALL:

I recently purchased a new server. I tried this snippet of code on it and everything worked well - but the execution failed
Can anyone help please.

Code:
#!/usr/bin/perl
use warnings;
use strict;
use CGI qw(:standard);
use DBI;
#---------------------------------------------------------
sub Connect;
sub Insert;
sub Validate;
sub PostOnFly;
#---------------------------------------------------------
print header();
print start_html(title => "Bizz5" );
my( $val,%vals,$dbc );
$val = new CGI;
%vals = $val->Vars;
Validate();
$dbc = Connect("bizz","maha");
Insert($dbc);
$dbc->disconnect();
print end_html();
#---------------------------------------------------------
sub Connect
{
my($user,$pass) = @_;
my($dbc);
$dbc = DBI->connect("DBI:mysql:host=localhost;database=bizzhel_bizzhelper",$user,$pass,{PrintError=>0,RaiseError=>1} );
return $dbc;
}
#---------------------------------------------------------
sub Validate
{
foreach my $k( %vals )
{
if($vals{$k} eq "" )
{
if( $k eq "name" || $k eq "company" || $k eq "phone" || $k
eq " email" || $k eq "where" || $k eq "comments" ) {
print "<html><head>\n";
print "<script Language=\"JavaScript\">\n";
print " alert(\"All required fileds must be filled out\");\n";
print "history.back()\;";
print "</script></head></html>\n"; exit;
}
}
$vals{$k} =~ s/^\s+//;
$vals{$k} =~ s/\s+$//;
}
}
#---------------------------------------------------------
sub Insert
{
my($dbc) = @_;
my( $dbs,$count,$datetime,$pass,$user,$count,$number );

$dbs = $dbc->prepare("INSERT INTO franchise( name,company,email,phone,where,comments,password,username,datetime) VALUES(?,?,?,?,?,?,?,?,?)");
$datetime = localtime;
$count = 0;
$pass = "pass";
$user ="user";

srand(time|$$);

$number = int(rand(1000)) + 1;

$pass .= $number;

$number = int(rand(1000)) + 1;

$user .= $number;

THE CODE FAILS HERE.
-----------------------------

$count = $dbs->execute($vals{name},$vals{company},$vals{email},$vals{phone},$vals{where},$vals{comments},$pass,$user,$datetime);

if( $count != 0 )
{
&PostOnFly();
}
$dbs->finish();
}
#---------------------------------------------------------
sub PostOnFly
{
not done yet
}

Last edited by:

Andy: Oct 27, 2004, 1:14 AM
Quote Reply
Re: [TheSafePick] HELP WITH CODE In reply to
What were the errors when you tried to run it?

~Charlie
Quote Reply
Re: [Chaz] HELP WITH CODE In reply to
Hi:

There were no errors in specific to the code in my opinion. All the errors referenced something like missing files.

[Tue Oct 26 13:13:27 2004] [error] [client 68.111.167.12] File does not exist: /home/bizzhel/public_html/_vti_bin/owssvr.dll
[Tue Oct 26 13:12:15 2004] [error] [client 68.111.167.12] File does not exist: /home/bizzhel/public_html/404.shtml
[Tue Oct 26 13:12:15 2004] [error] [client 68.111.167.12] File does not exist: /home/bizzhel/public_html/MSOffice/cltreq.asp
[Tue Oct 26 13:12:15 2004] [error] [client 68.111.167.12] File does not exist: /home/bizzhel/public_html/404.shtml
[Tue Oct 26 13:12:15 2004] [error] [client 68.111.167.12] File does not exist: /home/bizzhel/public_html/_vti_bin/owssvr.dll
[Tue Oct 26 13:12:08 2004] [error] [client 68.111.167.12] File does not exist: /home/bizzhel/public_html/404.shtml

I am trying out a new server that uses cPanelX Control Panel. Maybe I will have to check the Mysql settings. Unfortunately my host is a business man and not very thenical.

Thanks,
Mike
Quote Reply
Re: [TheSafePick] HELP WITH CODE In reply to
Try using strict and test your connection to make sure you are even connecting:

Code:
#!/usr/bin/perl
use strict;
use warnings;
...

(from the DBI pod)
Code:
$dbh = DBI->connect($data_source, $username, $password, \%attr)
or die $DBI::errstr;

What exactly isn't working for you?
Quote Reply
Re: [Chaz] HELP WITH CODE In reply to
Thanks:

I've solved the problem. It seems that the field column "where" of the table franchise
is a reserved word. I changed and it worked like a charm.


Thanks