Gossamer Forum
Home : Products : DBMan : Customization :

last field empty but code displayed???

Quote Reply
last field empty but code displayed???
I have a database with the last field called "notes". As this field does not necessarily have a value, the code in html_record states
if ($rec{'notes') { print "blablabla"; }

For some reason, the code indicated with "blablabla" is ALWAYS printed, even when the field is empty. I was thinking that this may have to do with the field being the last one in the database. Perhaps dbman somehow considers the carriage-return at the end of the line in the db-file to be a field value? If so, how to get around this?

Cheers,

kellner
Quote Reply
Re: last field empty but code displayed??? In reply to
The way you have:

if ($rec{'notes') { print "blablabla"; }

You are telling the script to print blablabla if there is anything in the notes field. Except your print commands were missing the qq| and ending |;

If you want it to print out the contents of the field only if there is a value you would use:

if ($rec{'notes'}) {
print qq| $rec{'notes'} |;
}

Hope this helps

For more syntax questions and solutions, please visit the FAQ noted below.


Unoffical DBMan FAQ
http://webmagic.hypermart.net/dbman/
Quote Reply
Re: last field empty but code displayed??? In reply to
I was having the same problem - apparently, the database recognizes the last entry as always having a value, even if none exists - it thinks that there is a blank space there - " ". What I did to remedy the problem (provided you plan on entering notes of greater than 2 characters) was to use an if statement checking the length. Here's what you could do with yours:
Code:
if (length($rec{'notes'}) >= 3) {
print qq|blablabla|;
}

It's just a funny quirk within the system and this is probably the easiest way to solve it, for the empty space is only recognized with a length of 1.

=Blake=
http://www.movielocity.com

Quote Reply
Re: last field empty but code displayed??? In reply to
Blake's post solved the problem - thanks a lot.

Lois C, you got your perl syntax wrong. The print command works ALSO with double quotes - everything within double quotes is printed. Because you occasionally have to print strings that CONTAIN double quotes, you often (or always) use "print qq" for the sake of readability. The command print qq! blablabla ! prints out whatever is in between the two exclamation marks because there's a "qq" before the first - the "qq" marks the quotation mark as string delimitor. Anyway, whether there are quotation marks or whether "print qq" is used has got nothing to do with the problem under discussion.

cheers,

kellner
Quote Reply
Re: last field empty but code displayed??? In reply to
Although you've got the problem solved, I might mention the solution I used was to create a "blank" field as the last field in the database. I made it a hidden non-required field so it doesn't show up for the user and doesn't actually have a value stored, but since it's the last field, I can then work with the next to the last field without running into the problem you described.

Melanie
http://www.somemoorecats.com/
http://www.okhima.org/
Quote Reply
Re: last field empty but code displayed??? In reply to
I once had the same problem and was racking my brain for hours trying to find the solution.

It's actually a newline character between the first record, and the next one below it that is causing the problem.

Normally one would solve this by using the chomp ($var_name); function. But checking the length of the variable is a perfect solution.

Just thought you'd be interested in the true cause Smile

Cheers,

- Mark

Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: last field empty but code displayed??? In reply to
yes, i thought of that as well, but it seems more complicated to add a blank field to a db with about 5000 entries (and change the cfg-file) than merely changing one line of code in html.pl.

thanks for the response,



kellner
Quote Reply
Re: [kellner] last field empty but code displayed??? In reply to
Actually I found that if I make the following addition to sub split_decode in db.cgi it seemed to work for me.

After

$array[$i] =~ s/``/\n/g; # Change '' back to newlines..

add

$array[$i] =~ s/\s+$//g;

Nora
Nora @
www.baytides.ca