Gossamer Forum
Home : Products : DBMan : Installation :

How to add links or pictures to database?

Quote Reply
How to add links or pictures to database?
Is it possible to add an IMG tag in one of the data fields so that an image shows up in the output? Also, can I give that image an HREF tag so it is linkable?
Quote Reply
Re: How to add links or pictures to database? In reply to
There are so many possible variations in what you might want, that it's hard to tell you how to do it exactly. But, yes, it is possible to do what you want if you do not use the autogenerate feature. You will have to build you html_record yourself.

I'll give you the more common uses of image tags and URL tags and you should be able to take it from there.

Let's say you have a field with the name of the image you want displayed. We'll call it "Image."

In html_record you would use something like
Code:
<td><img src="http://full/url/to/image/directory/$rec{'Image'}"></td>

Similarly, to create a link, assuming you have a field called "URL" which has the full URL to the site you want to go to --

Code:
<td><a href="$rec{'URL'}">$rec{'URL'}</a></td>

So, if you put the two together, you would have
Code:
<td><a href="$rec{'URL'}">
<img src="http://full/url/to/image/directory/$rec{'Image'}">
</a></td>



------------------
JPD


[This message has been edited by JPDeni (edited February 21, 1999).]
Quote Reply
Re: How to add links or pictures to database? In reply to
JPDeni - one question about this ......
If I add the "Image" field in my %db_def will the "field_type" and "form_length" need to be set to anything?
Quote Reply
Re: How to add links or pictures to database? In reply to
You're not storing the actual image in the database, just the filename. So set field type to alpha and form length to the maximum size that the image filename will be.

Cheers,
adam

[This message has been edited by dahamsta (edited April 27, 1999).]
Quote Reply
Re: How to add links or pictures to database? In reply to
Thanks Adam -

Another question - how can I make this field (Image) so that only the admin can add to and modify this field?
Quote Reply
Re: How to add links or pictures to database? In reply to
 
Well, you can and you can't. With the single database, it would be almost impossible without a hefty bit of hacking. In fact I'm not sure you even could.

That said, there's a very easy way around it. Just create another config and html file. For example, copy your default.cfg file and call the copy admin.cfg. Now, in the copy change:

require $db_script_path . "/html.pl";

to:

require $db_script_path . "/admin.pl";

or whatever your equivalent is. Next, make a copy of html.pl and call it admin.pl. Now you can remove the Image field from the original html.pl and make it an optional field, so when the user goes to add a record, voila - no Image field. And if you want to add an image, you can access the admin version with:

http://yourserver.com/path/to/dbman/db.cgi?db=admin

Obviously you can only do this if you're creating your own pages, it won't work with auto_generate. And you might also want make another couple of changes to admin.cfg for security. Probably the safest bet is to use a different .pass file and set your permissions to keep everybody out.

Cheers,
adam
Quote Reply
Re: How to add links or pictures to database? In reply to
Thanks - I implemented your suggestion of an admin.pl and admin.cfg and the images work fine.

However, it has caused a different problem. I am using JPDeni's What's New mod - and when I click on the link to bring up the most recently added or modified records - get a list of images and incomplete text.
Quote Reply
Re: How to add links or pictures to database? In reply to
 
I'll have to leave that one to JPD. To be honest, I didn't even know there *was* a What's New mod. I'm off to have a look at it now!

Over to you Carol, and sorry if I busted it!

Smile

adam
Quote Reply
Re: How to add links or pictures to database? In reply to
There is another (and I think easier) way to go about this.

Use just one html.pl file. In sub html_record_form, in the place where you enter the name of the graphic, use the following:

Code:
|; # to close off a previous print qq| statement
if ($per_admin) {
print qq|<TR><TD>Image:</TD>
<TD><input type="text" name="Image" value="$rec{'Image'}"></TD></TR>|;
}
else {
print qq|<input type="hidden" name="Image" value="$rec{'Image'}">|;
}
print qq|

and then go on with your form definition.

Of course, you would need to change "Image" to the actual name of the field.

It would be possible for a user to download the form, change the value of the hidden field, load it back into his browser and add the record. I don't think that's very likely, though.


------------------
JPD





Quote Reply
Re: How to add links or pictures to database? In reply to
ok - I changed back to the single html.pl file according to JPDeni's last post.

It works as JPDeni said, however the "What's New" is still messed up.... the first few links are fine and then it looks like it begins to pull random text and lists it as links.

JPDeni - you are still listed in my database and you have all priviledges with exception of admin if you want to take a look at it.

The database is at http://cocoahighalumni.com/cgi-bin/dbman/db.cgi
Quote Reply
Re: How to add links or pictures to database? In reply to
I didn't have a problem with "What's New," but I did have a problem with "List All." Lots of odd stuff there! Smile

I'm wondering if you created a place in your old records for the new field. If there aren't enough field delimiters to match the number of defined fields, you're going to have a problem.

Assuming you added the "Image" field at the end of your database, you need to go through and add another delimiter to the end of each of the records that have not been recently modified. It's gonna be a bear to do, since some of them have the right number of fields and some don't.

You might be able to pull up each record individually that was last modified before you added the field and, without changing anything, click the "Modify Record" button. But with 900+ records, that's gonna take you a long time, too.

The only other thing I can suggest is to download the database and import it into something like MSAccess. It might take the data, even though there aren't the same number of fields in each row. This has some problems of its own, though.

BTW, adam, the "What's New" mod has been in the forum. I haven't gotten around to making a file for it. Guess I'll have to do that tonight.


------------------
JPD





Quote Reply
Re: How to add links or pictures to database? In reply to
 
Quote:
almost impossible without a hefty bit of hacking. In fact I'm not sure you even could

See? I'll bet that JPD hack took you all of five minutes to get running right! Smile

Sorry, permissions were never my strong point... Frown

adam
Quote Reply
Re: How to add links or pictures to database? In reply to
Don't feel too bad, Adam. I've been reading your posts in the Perl/CGI forum and you've been very helpful.

BTW, I got the "What's New" mod up on my site. It's at
http://www.jpdeni.com/dbman/whatsnew.txt



------------------
JPD





Quote Reply
Re: How to add links or pictures to database? In reply to
Thanks to both of you for your help ! It took me awhile to respond this last time because I remembered I hadn't made changes to the database file itself (adding the new field delimiter).

Whew !! 900+ records takes quite awhile - but everything is corrected now !

Thanks again - the help you give is always great !