SpritusMaximus has asked for the wisdom of the Perl Monks concerning the following question:
Fellow monks,
I have an odd database problem. I'm implementing user registration on my website; in my user validation, I have code like this:
UPDATE: Thanks for the hints, everyone. I should have clarified earlier that I actually tried to select the rows and then count them, then I read the CPAN warning and decided to use SELECT COUNT(*) instead. In the end, removing the single quotes worked.
The problem is this: I can never get the $Statement to return anything when selecting a Nickname I know exists. If I try this in the mysql monitor (using the same user login and machine as this script runs on, and the exact same query), I get back one row; but inside this script, nothing. I've also tried my $NumRows = $Statement->rows but that always returns zero rows. I'm using CGI.PM with fatalstobrowser. I tried modifying the username, and it expectedly spits out a database login error with the modified username - but with the "correct" username, I get nothing. I've done things like this before without a problem. Where can I look that would give me an indication of what is breaking down?$SQL = "SELECT COUNT(*) FROM Members WHERE Nickname = '?'"; $Statement = $Database->prepare($SQL); $Statement->execute($NickName); my @numrows = $Statement->fetchrow_array; rint "NumRows: @numrows"; if (($Statement->rows) > 0) { LogError("NICK_TAKEN"); return("-1"); }
UPDATE: Thanks for the hints, everyone. I should have clarified earlier that I actually tried to select the rows and then count them, then I read the CPAN warning and decided to use SELECT COUNT(*) instead. In the end, removing the single quotes worked.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Odd Database Behavior
by bart (Canon) on Dec 15, 2003 at 17:06 UTC | |
Re: Odd Database Behavior
by hardburn (Abbot) on Dec 15, 2003 at 17:19 UTC | |
Re: Odd Database Behavior
by tcf22 (Priest) on Dec 15, 2003 at 17:06 UTC | |
Re: Odd Database Behavior
by Abigail-II (Bishop) on Dec 15, 2003 at 17:11 UTC | |
Re: Odd Database Behavior
by Roy Johnson (Monsignor) on Dec 15, 2003 at 17:06 UTC | |
Re: Odd Database Behavior
by pg (Canon) on Dec 15, 2003 at 17:15 UTC | |
Re: Odd Database Behavior
by grinder (Bishop) on Dec 15, 2003 at 20:15 UTC |
Back to
Seekers of Perl Wisdom