mnlight wrote:
Can anyone explain why I am recieving this error.
Use of uninitialized value in concatenation (.) or string at Signup.pl line 46...
The short answer is "yes, I can explain why." You have an unitialized value in a concatenation or string. The longer answer is, "no, I don't know why you have an unitialized value." I don't know what your line numbers are, so I can't tell where the value is. Further, while I could try to figure out the offsets from your error messages and correlate those to print statements in your code, I'm not going to do that.
If you have a halfway decent editor (no, I'm not talking about Notepad), you should be able to see your line numbers. Since you're not using HERE docs (which can obscure the problem), you should be able to point almost perfectly to the line where you have an unitialized value. For example:
$ perl -e '
use strict;
use warnings;
my $x;
print $x;'
Use of uninitialized value in print at -e line 5.
I can see at a glance that the lone print statement is line 5 and, if I had a problem, I could tell the monks "Look, there's where I get the error".
So, try reporting where the error is and we'll try to narrow it down for you (though I suspect that it lies in your SQL returning nothing).
Update: I tried refactoring and cleaning up your code a little bit:
$user = $dbh->quote( $user );
my ( $field, $sub_parent ) = $parent eq 'Father'
? ( 'Father', "'Mother'" )
: ( 'Mother', "'Father'" );
$sth = $dbh->prepare ("select $field from Roster where User = $user");
$sth->execute ();
my $name = $sth->fetchrow_array;
if ($name eq ""){
$sth = $dbh->prepare ("select $sub_parent from Roster where User =
+ $user");
$sth->execute ();
$name = $sth->fetchrow_array;
} #end chk for not parent if statement.
print $query->h1({-align=>'center'},"THANK YOU FOR SIGNING UP $name");
$sth = $dbh->prepare ("select distinct Volunteer from Volunteer where
+Volunteer = ? and Date = ?");
foreach my $date ( @volunteer_date )
{
$sth->execute ( $name, $date );
my $chk = $sth->fetchrow_array;
if ($chk eq $name)
{
print $query->h1({-align=>'center'}, "You are already signed u
+p for this date: $date");
} #end if statement
else
{
$sth = $dbh->prepare ("select max(Number) from Volunteer where
+ Date = ? and Volunteer = 'TBD'");
$sth->execute ($date );
After doing this, I saw that you are not using strict and you have some serious scoping issues. These scoping issues make this difficult. As I see from your code below, the problem lies in $user not being initialized.
$sth = $dbh->prepare ("select Mother from Roster where User = \'$user\
+'");
Thus, your problem occurred before the snipped that you presented us with. Also, note in my cleanup above that I used the $dbh->quote method. This will save you much grief, rather than trying to escape the data with single quotes (if the data contains single quotes, your escaping it will fail, for example). I suggest you read the DBI documentation very carefully.
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats. |