Gossamer Forum
Home : Products : DBMan : Customization :

Variables galore!

Quote Reply
Variables galore!
I am using sendmail in one of my subroutines in the db.cgi.

This part works great:
print MAIL "$in{'Name'} has placed an entry into the database. $in{'Description'} ";

Soon as I try to do this:
$message = "$in{'Name'} has placed an entry into the database. $in{'Description'} ";

print MAIL "$message";

The description part doesn't work but the name and text does. I've tried so many combinations, including swapping out $in with $rec.

I am completely baffled. It has to do with the varibles somehow, because I can always get it to work properly without them. But I really need this to work:

print MAIL "$message";

Anyone have a clue as to what I'm doing wrong ?


Quote Reply
Re: Variables galore! In reply to
What do you mean by "it doesn't work"? Nothing shows up? Blankness?

The only thing I can think of is that maybe you have misspelled something. Unless you copied the code directly from your script.

Sometimes what appears to be the problem isn't really the cause of it, though. Could you post a little more of the code, before and after the $message = line?


------------------
JPD





Quote Reply
Re: Variables galore! In reply to
Yeah, it show's up as blank.
Here is what works:
Code:
open (MAIL, "|/usr/lib/sendmail -t") or &cgierr("can't get to sendmail. reason: $!");
print MAIL "To: $in{'Email'}\n";
print MAIL "$in{'Name'} has placed an entry into the database. $in{'Description'}";
close MAIL;

But this does not work:
In my default.cfg I included this:
$message = "$in{'Name'} has placed an entry into the database. $in{'Description'} ";

and I try to print it like this:
Code:
open (MAIL, "|/usr/lib/sendmail -t") or &cgierr("can't get to sendmail. reason: $!");
print MAIL "To: $in{'Email'}\n";
print MAIL "$message";
close MAIL;

I don't receive any errors, it just doesn't print the description. It's blank.

And it's driving me batty.
Quote Reply
Re: Variables galore! In reply to
What if I were to have db.cgi run the sendmail from another file. Instead of running the sendmail from inside db.cgi, maybe I could have it run from another file.

If I launched &send_the_email from inside db.cgi, how do I get it to return to db.cgi after it's done sending the mail ? Is the perl command called return; ?

[This message has been edited by Katana Man (edited June 01, 1999).]
Quote Reply
Re: Variables galore! In reply to
Hi Katana Man,

I'm only speculating here, but I think that putting the $message variable in your config file won't work because it can't access the %in hash. But if that's the case, it should just print:

"has placed an entry into the database."

...with neither veriable displayed. Is that what's happening?

See, up the top of db.cgi, it says:

local(%in) = &parse_form;

Which parses the form and puts the data in the %in hash. And just after that if figures out which .cfg file to use and requires it. But because %in has been declared as local, you can't access that data from the cfg file. I'm not sure if it's ok to remove the localization of the variable, but maybe you could give that a go:

%in = &parse_form;

Then again, I could be utterly wrong... Smile

Cheers,
adam
Quote Reply
Re: Variables galore! In reply to
dahamsta,

Thanks so much for your reply. I tried to remove it, and I also tried to undef %in, but it had too many side effects. Wehn I removed it, I couldn't log in, when I undefined it, none of the variables worked.

To add more info, the $in{'Name'} works, but the $in{'Description'} doesn't. Now to make it even weirder, there are other variables that do work, and others that don't. For example, I had trouble with $in{'Category'} but the $in{'Date'} would work.

I can't figure out why this is acting like this. There should be no reason why perl can't handle variables inside variables.
Quote Reply
Re: Variables galore! In reply to
Yup, that *is* weird, but no doubt Alex or someone will come along and explain it shortly and we'll all go, "Ooooh! Why didn't I see that?".

Since you're able to get some of the values from the hash, I don't know why I'm suggesting this, but maybe you could try creating a global hash from %in:

%globalin = %in;

Sorry I can't be more help.

adam
Quote Reply
Re: Variables galore! In reply to
Strange indeed! If you are getting one but not the other, I'd really think it's a typo. What happens if you move the $message = .. line to just before you send the message (i.e. not in the config). Does that work?

Cheers,

Alex
Quote Reply
Re: Variables galore! In reply to
Nope, it's not a typo. I've been stumbled by this for 3 days now.

I just noticed that there are a bunch of $message variables in the db.cgi, so I got all excited thinking I'd fix it by changing the name of the variable. I changed it to:

$thedog = "Hi $in{'Name'}, here is the description $in{'Description'}";

Still no luck. You are right Alex, If I put it directly infront of the sendmail section, it does work, but is defeating the purpose of putting variables in the default.cfg file.

Here is some more info. These are just some examples that I tested:
$in{'Name'} works fine.
$in{'Description'} does not.
$in{'Subject'} works fine.
$db_dir_url works fine.
$db_script_url does not.
&get_time does not.

swapping $in with $rec is no help either.

-A baffled and confused Katana Man.

[This message has been edited by Katana Man (edited June 01, 1999).]
Quote Reply
Re: Variables galore! In reply to
Using $rec instead of $in definitely won't work. The %rec hash is defined much later than variables in your .cfg file.

It's also odd that $db_dir_url works and $db_script_url doesn't. Where in your .cfg file are you defining your $message variable?


------------------
JPD





Quote Reply
Re: Variables galore! In reply to
The $db_dir_url and $db_script_url are next to eachother at the top of default.cfg
I've tried pulling the subroutines out of the db.cgi and putting them into a clean file, but it's the same thing. I've moved the variables and renamed them, but to no avail.

To see this for in action for yourself, in the db.cgi, in sub add_record, add the following code right before &html_add_success
Code:
open (MAIL, "|/usr/lib/sendmail -t") or &cgierr("can't get to sendmail. reason: $!");
print MAIL "To: $in{'Email'}\n";
print MAIL "From: $in{'Email'}\n";
print MAIL "$in{'Name'} has placed an entry into the database. $in{'Description'}";
close MAIL;

This will work, but soon as you try to define
$thedog = "Hi $in{'Name'}, here is the description $in{'Description'}";
into default.cfg or another file, and try to use it, things start to go silly.


Code:
open (MAIL, "|/usr/lib/sendmail -t") or &cgierr("can't get to sendmail. reason: $!");
print MAIL "To: $in{'Email'}\n";
print MAIL "$thedog";
close MAIL;

[This message has been edited by Katana Man (edited June 02, 1999).]
Quote Reply
Re: Variables galore! In reply to
If anyone tries this recent suggestion and it works, please let me know. My initial reaction is that it will not work on NT servers if you are using the Mailer.pm module. But I could be wrong.

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: Variables galore! In reply to
I haven't read this thread thouroughly as I have to run out, but if you just want to be notified when someone adds to the database then why not add the MAIL command in html.pl in the sub html_add_success. Then you can use the $rec{'variable'}. I apologize if that is not what you are getting at but that is how I notify myself of a record being added.

My code:

open(MAIL,"|$mailprog -f$admin_email -t")| |die "Can't open $mailprog!\n"; print MAIL "To: $admin_email\n";
print MAIL "From: $rec{'email'}\n";
print MAIL "Subject: Toastmasters Directory Addition\n\n";

print MAIL "New Addition by: $rec{'f_name'} $rec{'l_name'}\n";



close (MAIL);



Mike

[This message has been edited by mike1 (edited June 06, 1999).]
Quote Reply
Re: Variables galore! In reply to
The above code is on a unix machine. I have no idea about NT. And it does work on Unix.

Mike