Cristi Ocolisan wrote:
Hi everybody!

Hello Cristi,

[snip]


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.


This may not fix your immediate question but it will definately help you find it and save you headaches inthe future :)



Thank you,

Cristi





#!/usr/bin/perl -w



$| = 1;



use Gig;

use CGI ":all";

use DBI;

use strict; use warnings;




$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')};

You should use $dbh->quote() too quote each field instead of using single quotes yourself. Why? Well for instance What would the query do above if $username was foo'bar ? It'd break, and it could get worse, people could exploit it to executre their own queries to get your sensitive data or delete your data...




$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){

This is likely the problem : You are assigning $mes the value of one which if true so the first if message is what you'll get every time.

Try
 if ($mes == 1) { ... '==' is a numeric operator

$mesaj = "Imi pare rau, dar unul dintre campurile obligatorii nu este
completat...";


[snip]

HTH

Lee.M - JupiterHost.Net

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to