View Full Version : I need help in cgi script please!
BlueBird
12-03-2002, 06:34 PM
Create n index page entitled "Family Tree". The index page should have links to five programs and or forms that are used to help a user se information and do datebase maintenance.
Write program a PERL script that reads data from the form and appends it to your database file the record in question (database use flat file with fields delimited by ':')
An HTML form consists a various form elements such as text fieds, and check boxes, radio buttons, and so forth.
Design an iput form with a wide variety of form elements (be sure to use either check boxes or radio buttons and to use either menus or list along with various textfields, etc.)
Provides programs/links for the following actions:
1. Design an input form that accesses and displays individual's information in the database, incorporating the following data-entry fileds:
-First name
-Last name
-Birth date
-Mother
-Father
-Comments (unrestricted number of comments)
2. List all entries in the database
3. Enter a new person (must be ralated to that which already exist)
4. Edit an existing person
5. Delete a person
6. Clear (clear the input form)
Anyone good in cgi please help me out with this one. Thank you in advance!
aznblood
12-04-2002, 11:05 AM
la`m toi' dda^u roi,
I am not really expert at perl, but good enough to create dynamic webpages like you've described.
First of all, there is too much to do, i dont know where to advice you. Do you need help w/ scripting, cgi-setup, database, or troubleshooting.......
If you will, Aim 'Dy I Dx' and i'll try to help you as you work on it.
good luck!
the task cu~ng easy la('m....if i were u..i would do it in PHP :)...but i guess for school project pha?i la`m in perl thi` chi.u kho' la`m ddi :)..hehehe if need anythin...post it out here....people will give advice for u :)
BlueBird
12-04-2002, 11:35 AM
I need help in database.
2. List all entries in the database
3. Enter a new person (must be ralated to that which already exist)
4. Edit an existing person
5. Delete a person
6. Clear (clear the input form)
Thank you in advance aznblood!
BlueBird
12-04-2002, 11:36 AM
I need to write them in perl and cgi.
hmmm.....
List all entries in the database
-> SELECT * FROM table_name
Enter a new person (must be ralated to that which already exist)
-> INSERT INTO table_name (column1, column2,...) VALUES (value1, value2,....)
and about the checking...you need to check before insert into the database...you can check the database by do a SELECT on the new person and if exist don't add...if not then add...
Edit an existing person
-> UPDATE table_name SET column_name = new_value
WHERE column_name = some_value
Delete a person
-> DELETE FROM table_name WHERE column_name = some_value
6. Clear (clear the input form) ...that you can set the <input type="reset" value="clear"> to clear it the box
if anything u need more detail...let me know...i be around :)...if need further..PM me...i give u my s/n....i can help u directly ..if needed
BlueBird
12-08-2002, 02:18 PM
Here my delete function but it doent work anyone can help me!
#!/usr/bin/perl -w
use CGI qw(:standard); #use GCI module
print header (),
start_html(-title=>'Family Tree',-text=>'blue',-bgcolor=>'tan') ,
h1 ({-align=>CENTER}, "Delete a Person in Database");
if (param())
{
my $lastname = param("Lname");
my $firstname = param("Fname");
my $birthday = param("Bdate");
my $father = param("Faname");
my $mother = param("Mname");
my $comments=param("comments");
#check if any data enter into the text box
if (($lastname eq "")&&($firstname eq ""))
{
&Addmenu;
print "Fillout person information to delete!";
&viewdata;
}
#check if missing lastname
elsif (($lastname eq "")&&($firstname eq param("Fname")))
{
&Addmenu;
print "Fillout their last name!";
&viewdata;
}
#check if missing first name
elsif (($lastname eq param("Lname"))&&($firstname eq ""))
{
&Addmenu;
print "Fillout their first name!";
&viewdata;
}
#read data from database file
else
{
open (DATA, "database.txt");
while(<DATA>)
{
$row = $_;
chop $row;
($dlastname,$dfirstname,$dbirthday,$dmother,$dfather,$dcomments) = split(/\:/,$row);
if ((param("Lname") ne $dlastname)&&(param("Fname") ne $dfirstname))
{
$new_row .= "$row\n";
}
}
close (DATA);
open(DATA,">>database.txt");
print DATA "$new_row";
close (DATA);
&Addmenu;
&viewdata;
}
}
else {
&Addmenu;
&viewdata;
}
sub Addmenu #add form
{
print hr();
print start_form();
print p (" Last Name:", textfield("Lname"));
print p (" First Name:",textfield("Fname"));
print p (submit ("Delete"), reset ("Clear"));
print end_form(), hr();
}
sub viewdata
{
print h2 ({-align=>CENTER}, "All Entries in the Database");
print hr;
open(DATA, "database.txt");
@lines=<DATA>;
close(DATA);
foreach $temp (@lines)
{
($lastname,$firstname,$birthday,$mother,$father,$comments) = split(/\:/,$temp);
if(($lastname eq '')&&($firstname eq '')&&($birthday eq '')&&($mother eq '')&&($father eq '')&&($comments eq ''))
{
print "Database empty!"
}
else
{
print "Last name: $lastname
First name: $firstname
Birth date: $birthday
Mother name: $mother
Father name: $father
Comments: $comments <br><hr>\n";
}
}
print hr;
}
Here my database file (database.txt) format look like:
Lastname:Firstnam:Birthday:Fathername:Mothername:Comments
hmm...delete function is a bit tricky...to delete a line from a file, use splice @line, $n, 1, or shift @line (to delete the first line) or pop @line (to delete the last line).
example:
Deleting one line is a little more difficult, since there is no command for it directly. What we have to do is read the contents of the file to an array, splice the line we want to delete from the array, and write the contents of the array to the file. If we go back to our 3-line file at the beginning of this section, this will overwrite what we had (3 lines) with what we send back (2 lines). So, if we want to delete the second line in the file, here is the code:
$sitedata="logfile.txt";
open(DAT, $sitedata) || die("Cannot Open File");
@raw_data=<DAT>;
close(DAT);
splice(@raw_data,1,1);
open(DAT,">$sitedata") || die("Cannot Open File");
print DAT @raw_data;
close(DAT);
thekeyboard
02-20-2003, 02:34 PM
Anyone know how to do this with Access? Rather than *.txt
vBulletin® v3.8.4, Copyright ©2000-2010, Jelsoft Enterprises Ltd.