Solved

NMS Guestbook problem

Posted on 2003-10-22
14
1,115 Views
Last Modified: 2013-12-25
I've altered the NMS guestbook.pl script slightly so it prints the guests name with a hyperlink to their email address - instead of their homepage.

The problem I have is that if they leave out their email address (or it's invalid), their name isn't printed in the guestbook.

This is the altered code:

     if ($inputs{username}){
       if ($linkmail) {
         $_ .= qq(<a href="mailto:$escaped{username}">);
         $_ .= "$escaped{realname}</a>";
       } else {
         $_ .= "$escaped{realname}";
       }
     }

     if ($inputs{'url'}) {
       $_ .= qq(<a href="$escaped{'url'}"> - Homepage</a>);
     } else {
       $_ .= " ";
     }

This is from the NMS version of the Matt's script archive guestbook.pl

Any ideas?
0
Comment
Question by:uksupafly
  • 7
  • 7
14 Comments
 
LVL 1

Expert Comment

by:robysath
ID: 9634931
I noticed that you are putting $escaped{username} instead of $escaped{'username'}

and $escaped{realname} instead of $escaped{'realname'}
0
 

Author Comment

by:uksupafly
ID: 9635243
I've tried this and I'm afraid I still get the same problem.
0
 
LVL 1

Expert Comment

by:robysath
ID: 9635810
Regarding first line:
" if ($inputs{username}){ "

if 'username' contains the e-mail (but none is entered by the user) then the very first if check fails and nothing will happen at all.
0
 

Author Comment

by:uksupafly
ID: 9638114
I think I understand - I thought it was saying that if there's an email address it should be linked to the realname, but if not, only the name should be printed.  But it presently states that it should only print if threre's an email address.

Is there a simple way to get what I need?
0
 
LVL 1

Expert Comment

by:robysath
ID: 9639942
$_ .= qq(<a href="mailto:$escaped{username}">) if (defined $inputs{username} && $linkmail);
$_ .= "$escaped{realname}"
$_ .= "</a>" if (defined $inputs{username} && $linkmail);

if above doesn't work try:

$_ .= qq(<a href="mailto:$escaped{username}">) if (defined($inputs{username}) && $linkmail);
$_ .= "$escaped{realname}"
$_ .= "</a>" if (defined($inputs{username}) && $linkmail);
0
 

Author Comment

by:uksupafly
ID: 9640819
I've tried these but I get an error with both.

Here's the complete write guestbook section:

rewrite_file($guestbookreal, sub
{
   if (defined and /<!--begin-->/) {

     $_ = '' unless $entry_order;

     $_ .= "<b>Name:</b> ";

$_ .= qq(<a href="mailto:$escaped{username}">) if (defined($inputs{username}) && $linkmail);
$_ .= "$escaped{realname}"
$_ .= "</a>" if (defined($inputs{username}) && $linkmail);

     if ($inputs{'url'}) {
       $_ .= qq(<a href="$escaped{'url'}"> - Homepage</a>);
     } else {
       $_ .= " ";
     }

     $_ .= "<br />\n";

     if ($inputs{city}){
       $_ .= "<b>City:</b> $escaped{city} ";
     }

     if ($inputs{state}){
       $_ .= $escaped{state};
     }

     if ($inputs{country}){
       $_ .= "<b>Country:</b> $escaped{country}  ";
     }

     $_ .= "<br /><b>  Date:</b> $date<br />\n";

     if ($separator) {
       $_ .= "<b>Comments:</b> $comments<HR width=550 SIZE=3>\n\n";
     } else {
       $_ .= "<b>Comments:</b> $comments<p />\n\n";

     }

     $_ .= "<!--begin-->\n" unless $entry_order;
   }
});
0
 

Author Comment

by:uksupafly
ID: 9640827
This is the live version:

rewrite_file($guestbookreal, sub
{
   if (defined and /<!--begin-->/) {

     $_ = '' unless $entry_order;

     $_ .= "<b>Name:</b> ";

     if ($inputs{username}){
       if ($linkmail) {
         $_ .= qq(<a href="mailto:$escaped{username}">);
         $_ .= "$escaped{realname}</a>";
       } else {
         $_ .= "$escaped{realname}";
       }
     }

     if ($inputs{'url'}) {
       $_ .= qq(<a href="$escaped{'url'}"> - Homepage</a>);
     } else {
       $_ .= " ";
     }

     $_ .= "<br />\n";

     if ($inputs{city}){
       $_ .= "<b>City:</b> $escaped{city} ";
     }

     if ($inputs{state}){
       $_ .= $escaped{state};
     }

     if ($inputs{country}){
       $_ .= "<b>Country:</b> $escaped{country}  ";
     }

     $_ .= "<br /><b>  Date:</b> $date<br />\n";

     if ($separator) {
       $_ .= "<b>Comments:</b> $comments<HR width=550 SIZE=3>\n\n";
     } else {
       $_ .= "<b>Comments:</b> $comments<p />\n\n";

     }

     $_ .= "<!--begin-->\n" unless $entry_order;
   }
});
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 1

Expert Comment

by:robysath
ID: 9642372
Oops, associative array, I should have said 'exists' instead of 'defined', try that instead.
0
 

Author Comment

by:uksupafly
ID: 9642940
I'm still getting a script error:

syntax error at guestbook.pl line 217, near "$_ " syntax error at guestbook.pl line 251, near "}" Execution of guestbook.pl aborted due to compilation errors
0
 
LVL 1

Expert Comment

by:robysath
ID: 9653414
try:

     if (($inputs{username}) and ($linkmail)) {
         $_ .= qq(<a href="mailto:$escaped{username}">);
         $lmail = 1;
     }
     $_ .= "$escaped{realname}";
     if ($lmail) { $_ .= "</a>"; }
0
 
LVL 1

Expert Comment

by:robysath
ID: 9653431
Instead of:

if ($lmail) { $_ .= "</a>"; }

you can also say:

$_ .= "</a>" if ($lmail);
0
 

Author Comment

by:uksupafly
ID: 9654511
Thanks again but I'm afraid I'm still getting errors:

Global symbol "$lmail" requires explicit package name at guestbook.pl line 217. Global symbol "$lmail" requires explicit package name at guestbook.pl line 220. BEGIN not safe after errors--compilation aborted at guestbook.pl line 682
0
 
LVL 1

Accepted Solution

by:
robysath earned 250 total points
ID: 9654824
Then try:

   if (($inputs{username}) and ($linkmail)) {
         $_ .= qq(<a href="mailto:$escaped{username}">);
         $main::lmail = 1;
     }
     $_ .= "$escaped{realname}";
     $_ .= "</a>" if ($main::lmail);
0
 

Author Comment

by:uksupafly
ID: 9654896
That's it!   thanks very much, works a treat.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
This article will show, step by step, how to integrate R code into a R Sweave document
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now