Previous Thread
Next Thread
Print Thread
Rate Thread
Joined: Apr 2001
Posts: 28
Junior Member
Junior Member
Offline
Joined: Apr 2001
Posts: 28
I have the following in my CGI script. If customfield1 is blank then I want customfield1 to change its value and equal $vars_config{NonCGIURL}/avatar-generic.gif. But if customfield1 is NOT blank then I do not want customfield1 to change at all.

$CustomField1 = $user_profile[20]

if( $CustomField1 eq '') {
$CustomField1 = qq($vars_config{NonCGIURL}/avatar-generic.gif);
} else {
$CustomField1 = $user_profile[20];
}

I tried the above perl code but it seems to not be working. My AIM is JZollo66 and I will be on throughout the day attempting to solve this problem.

This is for a new Avatar hack that allows users to define their own avatar from a URL. Anyone who helps me gets the hack first.

[ May 05, 2001 09:52 AM: Message edited by: JZollo66 ]

Sponsored Links
Joined: Aug 2000
Posts: 335
Member
Member
Offline
Joined: Aug 2000
Posts: 335
That code looks correct, assuming that $vars_config{NonCGIURL} is defined, and that the missing semicolon is just a typo here.

What does "seems to not be working" mean?

You could simplify it a little:

Code
code:

Joined: Apr 2001
Posts: 28
Junior Member
Junior Member
Offline
Joined: Apr 2001
Posts: 28
Allow me to explain, my seems to be ignoring that "if" statement and just going with $CustomField1 = $user_profile[20];

$user_profile[20] is defined. If the user doesn't put something down when they sign up then it is blank. If they do not put a URL down for their custom avatar then I want a generic image to appear.

In my HTML it looks like this - If the user did define their value then their value should show up, if they didn't then a generic image should show up.

Basically, if $user_profile[20] is blank, then I want to change its value to $vars_config{NonCGIURL}/avatar-generic.gif

Is this possible ?

Joined: Aug 2000
Posts: 335
Member
Member
Offline
Joined: Aug 2000
Posts: 335
This sounds like it may be more of a UBB mod question than a Perl question, so maybe posting it in the mod questions forum would get a more accurate response.

If an 'if' doesn't appear to be having an effect, the way to troubleshoot it is to add 'print' or 'warn' statements around the problem area to see exactly what the variables are getting set to.

Another possibility is that your code isn't located in the right place in the script, so the change you're making isn't getting saved.

If it's really $user_profile[20] that needs to be updated, perhaps you meant to do this:

Code
code:

Joined: Jan 2001
Posts: 184
Member
Member
Offline
Joined: Jan 2001
Posts: 184
Quote
quote:
Simply remove: $CustomField1 = $user_profile[20]

Your code set a variable and then checks to see if it equals nothing? Either move that line to the beginning to serve as a default if code later on sets it. Or, kill it as I suggest and let the if/else statements set it accordingly. It's the positioning that matters if your code is used (btw, add a semi-colon on the end of that 1st line).

I always advise setting a default at the beginning of source to compensate for any missing future file or user input errors/conditions. Later on, check for values and set conditionally. If no conditions are met, the value is the default. Your else condition essentially does that, so either method will work, but your method obviously cannot.

When you define defaults for variables, think ahead as to possible mistakes. The default should always be a "fallback" setting if literally, all else fails. You can even use defaults to see if other routines failed. Defaults are good, if used properly. But positioning is the key.

-Jim

Sponsored Links
Joined: Oct 2000
Posts: 743
Moderator / Code Fixer
Moderator / Code Fixer
Offline
Joined: Oct 2000
Posts: 743
Don't you get a server error? as you forgot the semi colan on the end of the first line
$CustomField1 = $user_profile[20]


I can't afford a good signature editor frown

Link Copied to Clipboard
Donate Today!
Donate via PayPal

Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.

Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
Recommended Hosts
We have personally worked with and recommend the following Web Hosts:
Stable Host
bluehost
InterServer
Visit us on Facebook
Member Spotlight
AllenAyres
AllenAyres
Texas
Posts: 21,079
Joined: March 2000
Forum Statistics
Forums63
Topics37,573
Posts293,925
Members13,849
Most Online5,166
Sep 15th, 2019
Today's Statistics
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
Top Posters
AllenAyres 21,079
JoshPet 10,369
LK 7,394
Lord Dexter 6,708
Gizmo 5,833
Greg Hard 4,625
Top Posters(30 Days)
Top Likes Received
isaac 82
Gizmo 20
Brett 7
Morgan 2
Top Likes Received (30 Days)
None yet
The UBB.Developers Network (UBB.Dev/Threads.Dev) is ©2000-2024 VNC Web Services

 
Powered by UBB.threads™ PHP Forum Software 8.0.0
(Preview build 20221218)