###################################################################### # script: db.cgi # # sub get_email # # # # new subroutine # # # # What it does-- # # Pulls the email address from the users table when a user adds # # a new record. # # # # How to use it-- # # In sub html_record_form, after # # my (%rec) = @_; # # add # # if ($in{'add_form'}) { # # $rec{'Email'} = &get_email; # # } # # # # Be sure to change the word 'Email' above to match exactly the # # name of the field that holds the user's email address. # # # # Important!! # # This only gets the email address for the currently logged in # #user. # # # # ULTRA IMPORTANT!!!!!!!!!!!!!!!!! # # Do NOT use this as the default value for a field in the .cfg file. # # You must use it as above. Leave the default value for this field # # empty. # ###################################################################### sub get_email { # -------------------------------------------------------- # Pulls the email address from the users table in your SQL database. my ($message, $userid, $pw, $view, $add, $del, $mod, $admin, $email, $password, $found, $output, $pass, $query); my $username_q = $DBH->quote($db_userid); $query = qq! SELECT * FROM $db_table_user WHERE username = $username_q !; my $sth = $DBH->prepare($query); $sth->execute(); if ($sth->rows) { while (@data = $sth->fetchrow_array) { $email = $data[2]; } } $sth->finish; return $email; }