Gossamer Forum
Home : Products : Links 2.0 : Customization :

What Am I Doing Wrong?

Quote Reply
What Am I Doing Wrong?
I posted this questions earlier, but thought if I displayed the code I was using, it would be easier to get help.

Background: I have added a field to the CATEGORY database called AllowSubmit, which is a Yes/No field. The object is, using hard-coded categories, if a person tries to submit to a category that AllowSubmit is set to NO on, it will display a message telling the submitter to go deeper into the directory.

Problem: I am unable to access the new field.

I have the following code placed in site_html.pl before it displays the add screen. $category is the name of the Category and I know this variable is set correctly because it is working within this same routine. Field 8 in my category.db is the AllowSubmit field.

Code:
open (DB, "<$db_category_name") or &cgierr("error in validate_records. unable to open db file: $db_file_name. Reason: $!");
LINE: while (<DB> ) {
(/^#/) and next LINE;
(/^\s*$/) and next LINE;
chomp;
@data = &split_decode($_);
if ($data[1] eq $category {
$allow = $data[8];
last LINE;
}
}
close DB;

if ($allow eq 'NO') {
&reject_submit
}

The odds are it is something small that I am missing.
Quote Reply
Re: What Am I Doing Wrong? In reply to
Hi Lee,

On first glance it looks ok. What is the problem? What do you mean "I am unable to access the new field"?

Describe what happens when you go to the add form and I'll try and help out.

Cheers,

Alex
Quote Reply
Re: What Am I Doing Wrong? In reply to
Thanks Alex ...

I took the above script and ran it as a standalone script (hardcoding the variables like the path to categories.db and $category) to make sure what I was doing I was doing correctly.

Along with the script, I had it print out all the variables I included to make sure they were being assigned properly, those variables being $data[x] and $allow. When it prints out the variables, every one of them equals "".

I am new to databases and perl, and I just can't figure out how to assign $allow with the field AllowSubmit in the category.db.

[This message has been edited by Lee (edited March 11, 1999).]
Quote Reply
Re: What Am I Doing Wrong? In reply to
I think I see the problem! &split_decode looks at what .def file you have loaded. It may not decode properly if you have links.def required. What I would do is just:

@data = split /\|/, $_, 9;

where 9 is the total number of fields in your database + 1.

Hope that helps,

Alex
Quote Reply
Re: What Am I Doing Wrong? In reply to
Alex, still no luck. Here is the code as I have it right now:

Code:
# Let's check to make sure we can submit a link to that category
open (DB, "<$db_category_name") or &cgierr("error in validate_records. unable to open db file: $db_file_name. Reason: $!");
LINE: while (<DB> ) {
(/^#/) and next LINE;
(/^\s*$/) and next LINE;
chomp;
@data = split /\|/, $_, 9;
if ($data[1] eq $category) {
$allow = $data[8];
last LINE;
}
}
close DB;
if ($allow eq 'No') {
&more_specific;
}

Any further suggestions?
Quote Reply
Re: What Am I Doing Wrong? In reply to
data[1] contains the last record of the database. Frown
Quote Reply
Re: What Am I Doing Wrong? In reply to
Does this offer any clues? ...

I got thinking that perhaps $db_category_name isn't assigned at that point and it wasn't checking the database. So, I assigned $catdir with the path to category.db and used open (DB, "<$catdir"). When I do that, I get an error message saying it is unable to find LINKS.db.

hmmmm
Quote Reply
Re: What Am I Doing Wrong? In reply to
Alternative method: Perhaps I am being redundant in the method I am using. Is it possible in sub category_list to aquire not only the category names, but my additional field (AllowSubmit) also at the same time?
Quote Reply
Re: What Am I Doing Wrong? In reply to
To see what's going on I would add:

print "Content-type: text/plain\n\n";

just before the open () call. Then add just after the split //:

print "comparing '$data[1]' with '$category' \n";

and just after the actual compare:

print "Matched!\n";

then run that and it should give you a better idea of what's going on..

Cheers,

Alex
Quote Reply
Re: What Am I Doing Wrong? In reply to
Man, this is frustrating.

Question: I am comparing a variable to info found in a database. Example: $category = 'Cars' and $data[1] = 'Cars' ... However; when I try if ($data[1] eq $name) {...} it does not = TRUE. Has anyone else ever had this happen and what do I do to correct it?

I have printed out both variables and they match (at least to the eye) and have tried chomping.

-----------

the saga continues ...

I just printed out the length of my variable $category (which = 'Business'). print length($category) returns 57!!!!! $category is obtained by using the hard-coded categories (environmental variable). Any idea what the extra hidden characters are at the end and what I can do to eradicate them from the face of this Earth?

[This message has been edited by Lee (edited March 14, 1999).]