Solved

NMS Guestbook problem

Posted on 2003-10-22
14
1,169 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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)

623 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