Gossamer Forum
Home : Products : DBMan : Customization :

Record in my email is not showing (SEND EMAIL AFTER A RECORD IS ADDED MOD)

Quote Reply
Record in my email is not showing (SEND EMAIL AFTER A RECORD IS ADDED MOD)
I have installed the "Send email after a record is added mod" which sends me (Admin) an email whenever a new item is posted. I do receive an email but it only contains this: The following new record has been added to the database: (there is no record!!)

I think the problem is within these lines in sub html_add_success:

my (%rec) = &get_record($in{$db_key});

open (MAIL, "$mailprog") || &cgierr("Can't start mail program");
print MAIL "To: $admin_email\n";
print MAIL "From: $admin_email\n";
print MAIL "Subject: $html_title New Record\n\n";
print MAIL "The following new record has been added to the database:.\n\n";
foreach $col ($db_cols) {
print MAIL "$col -- $rec{$col}\n";
}
close (MAIL);




Can anybody check it for me? Any help will be greatly appreciated. Thanks
Quote Reply
Re: [lolabasyang] Record in my email is not showing (SEND EMAIL AFTER A RECORD IS ADDED MOD) In reply to
Try using:

foreach $column(@db_cols) {
print MAIL "$column: $in{$column}\n";

Instead of:

foreach $col ($db_cols) {
print MAIL "$col -- $rec{$col}\n";

If that does not work check out other examples in the FAQ in the section "Email"

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Record in my email is not showing (SEND EMAIL AFTER A RECORD IS ADDED MOD) In reply to
I'm not sure why you are even using @db_cols...it isn't needed when you already have %rec

Code:
print MAIL map { "$_ -- $rec{$_}\n" } keys %rec;

...should do the job.

Last edited by:

Paul: Jul 15, 2002, 3:22 AM
Quote Reply
Re: [Paul] Record in my email is not showing (SEND EMAIL AFTER A RECORD IS ADDED MOD) In reply to
Paul, if you get bored can you give us a brief explanation of what the above is doing? Thanks!
Quote Reply
Re: [Watts] Record in my email is not showing (SEND EMAIL AFTER A RECORD IS ADDED MOD) In reply to
>>
print MAIL map { "$_ -- $rec{$_}\n" } keys %rec;
<<

Sure,

map is a bit like a loop in some ways, it will "loop" through the hash and set each element to $_ on each iteration so say %rec looked like:

%rec = ( ID => 1, Title => 'Blah' );

....then on the first iteration $_ would be ID and on the second $_ would be Title (as we specified "keys %rec"), so as you probably know $rec{$_} will then print out the value...if it were plain text you'd see ... $rec{ID} and $rec{Title} but obviously those key names are stored in $_

So basically it loops though the hash and prints the key name (stored in $_) into the email and then the value $rec{$_} as well.

To just print the values you could do:

print MAIL map { $_ } values %rec;

...or just:

print MAIL join ", " values %rec;

...and same for the keys etc (which are the same as @db_cols)

Hope that was not too rambly :)

Last edited by:

Paul: Jul 15, 2002, 8:23 AM
Quote Reply
Re: [Paul] Record in my email is not showing (SEND EMAIL AFTER A RECORD IS ADDED MOD) In reply to
Not too rambly at all. So this is why we use
$rec{'fieldname'} when working with data from default.db and why we use $in{'fieldname'} when using data that is being input into a form (but not yet saved) or data that comes from the URL string such as:

http://domain.com/cgi-bin/db.cgi?db=default&fieldname=blah

Cool.
Quote Reply
Re: [Watts] Record in my email is not showing (SEND EMAIL AFTER A RECORD IS ADDED MOD) In reply to
>>
So this is why we use
$rec{'fieldname'} when working with data from default.db and why we use $in{'fieldname'} when using data that is being input into a form (but not yet saved) or data that comes from the URL string
<<

Yeah, %in is form input. %rec is a database record.
Quote Reply
Re: [Paul] Record in my email is not showing (SEND EMAIL AFTER A RECORD IS ADDED MOD) In reply to
And is the coding you are supplying available in all version of Perl. For instance it is compatible with Perl 5.003?

Just curious if you are making suggestions based on the version available on all servers.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Record in my email is not showing (SEND EMAIL AFTER A RECORD IS ADDED MOD) In reply to
>>
Just curious if you are making suggestions based on the version available on all servers.
<<

What makes you think 5.003 is available on all servers?

In answer to your question, yes.

Last edited by:

Paul: Jul 15, 2002, 1:22 PM
Quote Reply
Re: [LoisC] Record in my email is not showing (SEND EMAIL AFTER A RECORD IS ADDED MOD) In reply to
I made that same change a while ago and it works perfectly...$ to @ (to make an array)

and if it ain't broke don't fix it
Quote Reply
Re: [mabel] Record in my email is not showing (SEND EMAIL AFTER A RECORD IS ADDED MOD) In reply to
>>and if it ain't broke don't fix it <<

Thats one approach but as someone who writes a lot of perl code, I opt for efficiency and cleanliness....if I can do something in one line, why would I do it in 3?

As a webmaster I would assume you'd want your site to be fast loading?....remember that the more code you use, the longer it takes to compile and the more server processing required.

I'm not saying "you must use my code"...I provide it because I enjoy writing it, take it or leave it, I still had fun Cool
Quote Reply
Re: [Paul] Record in my email is not showing (SEND EMAIL AFTER A RECORD IS ADDED MOD) In reply to
no, you're right, but i don't want to change it because i will probably break it if i do
Quote Reply
Re: [mabel] Record in my email is not showing (SEND EMAIL AFTER A RECORD IS ADDED MOD) In reply to
Have confidence in yourself :)