Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

NMS Guestbook problem

Posted on 2003-10-22
14
Medium Priority
?
1,196 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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
 
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 1000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will focus on how to use WhizBase as a tool for sending ICQ messages to ICQ. Here I will use a new technology in WhizBase, published in WhizBase 5.1 version. In this tutorial I will use 3 files, pager.wbsp for the processing, e…
Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

824 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