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;
}
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php