Hi everybody!
I'm trying to build a script that will insert some things into a MySQL
database.
My problem starts when I want to send the correct message into a webpage.
The webpage is in a package because I want to reuse it as a template.
My problem is that I can't make the script print the correct message into
the webpage.
Please tell me where I'm going wrong.
Thank you,
Cristi
#!/usr/bin/perl -w
$| = 1;
use Gig;
use CGI ":all";
use DBI;
$query = new CGI;
print $query->header;
$user = "root";
$pass = "";
$source = "DBI:mysql:ncp";
$dbh=DBI->connect($source, $user, $pass, {RaiseError => 1});
$nume = $query->param('nume');
$prenume = $query->param('prenume');
$oras = $query->param('oras');
$adresa = $query->param('adresa');
$judet = $query->param('judet');
$tara = $query->param('tara');
$telefon = $query->param('telefon');
$mobil = $query->param('mobil');
$email = $query->param('email');
$website = $query->param('website');
$cum_ne_ati_gasit = $query->param('cum_ne_ati_gasit');
$loc_munca = $query->param('loc_munca');
$functia = $query->param('functia');
$username = $query->param('username');
$parola = $query->param('parola');
$parola1 = $query->param('parola1');
if ($nume eq '' || $prenume eq '' || $oras eq '' || $adresa eq '' || $tara
eq '' || $telefon eq '' || $email eq '' || $username eq '' || $parola eq ''
|| $parola1 eq '') {
&eroare;
}
else{
$chestia = qq{select count(*) from persoane where username =
'$username'};
$sti = $dbh->prepare($chestia);
$sti->execute;
while (@gogu = $sti->fetchrow_array()){
if ($gogu[0] == 0){
if($parola ne $parola1){
&eroare_parola;
}
else{
$chestie = qq{INSERT INTO persoane VALUES(null, '$nume', '$prenume',
'$oras', '$adresa', '$judet', '$tara', '$telefon', '$mobil', '$email',
'$website', '$cum_ne_ati_gasit', '$loc_munca', '$functia', '$username',
'$parola')};
$sth = $dbh->prepare($chestie);
$sth->execute;
$mes = 1;
$dbh->disconnect;
}
}
else{
$mes = 2;
}
}
$sti->finish;
}
sub eroare {
$mes = 3;
}
sub eroare_parola {
$mes = 4;
}
The package is as follows:
I used " print <<HTML_; " because I have some JavaScript inside my webpage.
package Gig;
if ($mes = 1){
$mesaj = "Imi pare rau, dar unul dintre campurile obligatorii nu este
completat...";
}
elsif ($mes = 2 ){
$mesaj = "Imi pare rau, dar acest username exista deja.<br> Alegeti
altul, va rog!";
}
elsif ($mes = 3 ){
$mesaj = "Bla, bla, bla!";
}
elsif ($mes = 4){
$mesaj = "Parola nu este corecta. Introduceti va rog corect parola
identic in cele doua campuri.";
}
print <<HTML_;
<HTML>
<HEAD>
(.)
<TR>
<TD COLSPAN=2 ROWSPAN=33
background="images/index_46.jpg"> </TD>
<TD COLSPAN=15 ROWSPAN=33 valign="top"><div
align="justify">
<p class="style3 style6"
align=center><b>$mesaj</b></p> </div> </TD>
<TD ROWSPAN=33 background="images/index_49.jpg">
</TD>
<TD>
<IMG SRC="images/spacer.gif" WIDTH=1 HEIGHT=13
ALT=""></TD>
</TR>
(.)
</BODY>
</HTML>
HTML_