Problems with perl using CGI

0
Global symbol "$mysqli" requires explicit package name at register.cgi line 15.

Global symbol "$dbh" requires explicit package name at register.cgi line 30.

Global symbol "$dbh" requires explicit package name at register.cgi line 36.

register.cgi had compilation errors.

Seeing if the syntax of my perl script gives me those errors, I guess they are because I can not send another cgi file in which I have the database connection hosted ... for the moment I am working on a record and the code is this:

#!"C:\xampp\perl\bin\perl.exe"
require conexion.cgi;
use CGI;
use DBI;
use strict;
my $cgi = new CGI;
my $nombre = $cgi->param('f_name');
my $apellido = $cgi->param('l_name');
my $email = $cgi->param('email');
my $pass = $cgi->param('password');
my $mobile = $cgi->param('mobile');
my $adre1 = $cgi->param('address1');
my $adre2 = $cgi->param('address2');

my $sql = $mysqli->prepare("select user_id from user_info where email ='$email'");
my $con=$sql->execute() or die $DBI::errstr;
my $count=$con->rows;
if($count>0){
  print $cgi->header(-type=> 'text/html',
-charset=>'utf-8');
  print "<script>alert('El correo ya existe')</script>";
  print "
    <script>
      window.history.go(-1);
      exit;
    </script>';";
  return;
}
else{
  my $sth = $dbh->prepare("INSERT INTO user_info
                       (first_name, last_name,email, password,mobile,address1,address2)
                        values
                       ('$nombre', '$apellido', '$email', '$pass', '$mobile','$adre1','$adre2')");
  $sth->execute() or die $DBI::errstr;
  $sth->finish();
  $dbh->commit or die $DBI::errstr;
  print $cgi->header(-type=> 'text/html',
-charset=>'utf-8');
  print "<script>alert('Se registro exitosamente')</script>";
}
    
asked by Carlos Saz 08.10.2017 в 06:13
source

1 answer

1

It's because of "use strict;"

Perl warns you that you have just found a variable ($ mysqli) that has not been declared before, and if it is declared in another site, you must indicate "the name of the package" where it is.

    
answered by 09.10.2017 в 02:49