Gossamer Forum
Home : General : Perl Programming :

Free 4 All Links

Quote Reply
Free 4 All Links
Hi,

I just wrote a simple "Free 4 All Links" script:

Code:

#!/usr/bin/perl

$html1 = qq~
<!--VirtualAvenueBanner-->

~;

$html2 = qq~

<center><h1>Submit your link:</h1></center><br>

<form action="index.cgi" method=POST>
URL: <input type="text" name="URL" VALUE="http://"><br>
Title: <input type="text" name="Title"><br>
Description: <input type="text" name="Description"><br>
Your Name: <input type="text" name="Name"><br>
Your Email: <input type="text" name="Email"><br>

<input type="submit" value="Submit!">
</FORM>

~;

print "Content-Type: text/html\n\n";

use CGI;
$in = new CGI;
$field0 = $in->param('URL');
$field1 = $in->param('Title');
$field2 = $in->param('Description');
$field3 = $in->param('Name');
$field4 = $in->param('Email');

open (DATABASE_IN,">>url.db");
print DATABASE_IN "$field0|$field1|$field2|$field3|$field4\n";
close(DATABASE_IN);

open(DATABASE_OUT, "<url.db");
@entries = <DATABASE_OUT>;
close DATABASE_OUT;
print "$html1";
foreach $line (@entries) {
@fields = split(/\|/,$line);

print "<ul><li><a href=\"$fields[0]\">$fields[1]</a> - $fields[2]</li></ul>";

};
print "$html2";

Script in action: http://find.virtualave.net/02/index.cgi

But I've run into a BIG problem, whenever some one views the list, the script automatically submitts a 'blank' field to the database.

I can't figure out how to solve this. Smile Does any one knows the solution?

Regards,

Pasha

------------------
webmaster@find.virtualave.net
http://find.virtualave.net
Quote Reply
Re: Free 4 All Links In reply to
How did you learn how to make CGI scripts? I am trying to learn how to make scripts for perl. I want to start off with a banner rotator. Could you send me some tips or tell me how to learn?
this will be apprecialted. Smile
------------------
Patrick Chukwura
nytesoft.hypermart.net

[This message has been edited by niteridarz (edited March 24, 1999).]
Quote Reply
Re: Free 4 All Links In reply to
The best way to start (my experience) is to learn how to manipulate data. First program that I wrote was "Simple database engine" you can find it here in CGI forun, just look for "database engine" topic. Also, in that topic there're some good links to an online tutorials.

Regards,

Pasha

------------------
webmaster@find.virtualave.net
http://find.virtualave.net
Quote Reply
Re: Free 4 All Links In reply to
Hi Pasha,

Looks good, couple comments:

Code:
if ($in->param('URL') {
$field0 = $in->param('URL');
$field1 = $in->param('Title');
$field2 = $in->param('Description');
$field3 = $in->param('Name');
$field4 = $in->param('Email');
open (DATABASE_IN,">>url.db") or die $!;
print DATABASE_IN "$field0|$field1|$field2|$field3|$field4\n";
close(DATABASE_IN);
}

that way a new entry will be added only if a URL has been submitted.

Hope that helps, and good luck!

Alex

[This message has been edited by Alex (edited March 25, 1999).]
Quote Reply
Re: Free 4 All Links In reply to
Thanks Alex.
I don't use this error check, but it might be usefull. Thanks again. Smile


Regards,

Pasha

------------------
webmaster@find.virtualave.net
http://find.virtualave.net