List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:March 4 2003 10:25pm
Subject:Re: what is wrong with this perl mysql code?
View as plain text  
At 17:11 -0500 3/4/03, Jianping Zhu wrote:
>
>I am writing a simple login system by using perl( this is almost my first
>program in perl), After user pick a username i need to check if this
>username already exsited in mysql database table. if it is  already in
>the table, this program will prompt user to pick another user name.
>but something wrong with following code, the program does not work.
>   
>
>
>[code piece]***************************************
>my $selsql="SELECT * FROM apidbusers WHERE
> username=$username";       
>#prepare the query for $selsql
>
>my $selsth=$dbh->prepare($selsql);
>$selsth->execute();
>   if($selsth->fetchrow_array()) #*username already in apidbusers
>   {
>         print h4("This user name already registerd, please select
>              another user name.");
>         regstrForm();
>         return;
>   }
>***********************************************************************
>
>How to fix this problem?
>Any suggesion is appreciated.
>J.P.

Check your web server's error log to see what error your program
is generating.  Very likely it has something to do with not quoting
the $username variable properly.  I would try this:

[code piece]***************************************
my $selsql="SELECT * FROM apidbusers WHERE username=?"; # <- note change
#prepare the query for $selsql

my $selsth=$dbh->prepare($selsql);
$selsth->execute($username);                            # <- note change
   if($selsth->fetchrow_array()) #*username already in apidbusers
   {
         print h4("This user name already registerd, please select
              another user name.");
         regstrForm();
         return;
   }

Thread
How to tell when mysql has frozenSeth Brundle4 Mar
  • what is wrong with this perl mysql code?Jianping Zhu4 Mar
    • Re: what is wrong with this perl mysql code?Joshua J . Kugler4 Mar
  • Re: How to tell when mysql has frozengerald_clark5 Mar
Re: what is wrong with this perl mysql code?Paul DuBois4 Mar