#Search Records & Return Found 3 buttons
# 0 Member ID
# 1 Last Name
# 2 Business Name
elsif ($action eq "updatetable_167"){
warn("Entered updatetable_167");
my $kind = $query->param('kind');
my $searchterm = $query->param('searchterm');
my $result;
warn("searchterm = '$searchterm'");
my $searchfield = "";
if ($kind == 0) {
$searchfield = 'user_id';
}
if ($kind == 1) {
$searchfield = 'lastname';
}
if ($kind == 2) {
$searchfield = 'business';
}
warn("searchfield = '$searchfield'");
# my $stmt = "SELECT * FROM users WHERE $searchfield = ?"; comment out for testing
my $stmt = "SELECT * FROM users WHERE user_id = 15";
warn("statement = '$stmt'"); #of course meaning nothing with placeholder ?
my $sth = $dbh->prepare ($stmt) or die "Error Preparing:\n" . $stmt . "\nDBI returned: \n", $dbh->errstr;
$sth->execute($searchterm) or die "Unable to execute query: " . $sth->errstr;
warn("Finished sub search record");
$result = generateResponseHash($sth);
# code # below is used to populate an html table and sent back to the client. Works fine for testing
# $result = generateMemberDataSet($sth);
if ($result == 1) {
warn("Failed Search: '$searchfield' equal to '$searchterm' ");
}
}
####
sub generateResponseHash{
my $sth = shift;
$sth->execute () or die "Unable to execute query: " . $sth->errstr;
my $count = $sth->rows;
warn("count = '$count'");
if ($count == 0) {
return 1;
}
my $ref = $sth->fetchrow_hashref ();
# print "Hello Output File\n"; #test stdout redirect to dumper.log works.
warn("generateResponseHash ref: '$ref'");
my $hash = hash_display_listing ($ref);
$sth->finish ();
completeResultHash( $hash );
}
##
##
sub hash_display_listing{
my $ref = @_;
#warn("hash display_listing: '$ref->{"id"}'");
my $hash = (
'id' =>$ref->{"id"},
'user_id' =>$ref->{"user_id"},
'username' =>$ref->{"username"},
'password' =>$ref->{"password"},
'pin' =>$ref->{"pin"},
'position' =>$ref->{"position"},
'forename' =>$ref->{"forename"},
'lastname' =>$ref->{"lastname"},
'business' =>$ref->{"business"},
'address1' =>$ref->{"address1"},
'address2' =>$ref->{"address2"},
'city' =>$ref->{"city"},
'state' =>$ref->{"state"},
'zip' =>$ref->{"zip"},
'phone_home'=>$ref->{"phone_home"},
'phone_cell'=>$ref->{"phone_cell"},
'email' =>$ref->{"email"},
'comments' =>$ref->{"comments"},
'MJ' =>$ref->{"MJ"},
'MD' =>$ref->{"MD"},
'DD' =>$ref->{"DD"},
'DP' =>$ref->{"DP"},
);
print Dumper ($hash);
##
##
my $stmt = "SELECT * FROM users WHERE $searchfield = ?";
warn("statement = '$stmt'");
my $sth = $dbh->prepare ($stmt) or die "Error Preparing:\n" . $stmt . "\nDBI returned: \n", $dbh->errstr;
$sth->execute($searchterm) or die "Unable to execute query: " . $sth->errstr;