Help with creating Movies Database

T

TP

hi
this is my HTML page for the movie database
http://web.ics.purdue.edu/~tkhor/newdata.html

i get the function for search and list all movies to work but i dont get the
Add movies to work.
this is my source code for my cgi script

sub addrecord {
$NameText = $form{'NameText'};
$moviedescription = $form{'moviedescription'};
$moviecast = $form {'moviecast'};

$NameText=~s/</\&lt;/g;
$moviedescription=~s/</\&lt;/g;
$moviecast=~s/</\&lt;/g;

&open_file("FILE1",">>",$filename);

&write_file("FILE1",$NameText."|".$moviedescription."|".$moviecast."\n");
close(FILE1);

print"Content-type:text/html\n\n";
print"<html><head><title>Thank You </title></head>\n";
print "<body><br><h3><center>Thank you for adding
information</center></h3>\n";
print "<p>";
print"</body></html>\n";
exit;
}

* how should i modify the code so that i make it work?
* when i click on the show all function on the webpage , it seem that i wont
list the MOvie description ... so how can i fix this....

i am a newbie here with perl and cgi..so any help will highly
appreciate!!!!!!!!

thanks
 
M

Matt Garrish

TP said:
* how should i modify the code so that i make it work?

Ask whoever wrote that awful code how to fix it. This isn't a helpdesk for
buggy code you found on the Web.

Matt
 
T

Tad McClellan

TP said:
this is my source code for my cgi script


Are you using the CGI.pm module for decoding the form input?

You should have this near the top of your program, at least
during development:

#!/usr/bin/perl -T
use strict;
use warnings;
use CGI::Carp qw(fatalsToBrowser);


Each of those will help you write correct and secure programs.

Ask for all of the (machine) help you can get!

$NameText=~s/</\&lt;/g;
$moviedescription=~s/</\&lt;/g;
$moviecast=~s/</\&lt;/g;


Ampersand is not special in regexes, so you don't need to backslash it.

Whitespace is not a scarce resource, feel free to use as much as you
like to make your code easier to read and understand.

No need to write the same code three times, write it once,
and loop over it three times instead:

foreach ( $NameText, $moviedescription, $moviecast ) {
s/</&lt;/g;
}

(there are other characters that may need escaping you know...)

&open_file("FILE1",">>",$filename);


Don't use the ampersand on function calls unless you know what it
does, and what it does is what you want (it seldom is what you want).

You should always, yes *always*, check the return value from open():

open_file("FILE1", ">>", $filename) or
die "could not open '$filename' $!";

&write_file("FILE1",$NameText."|".$moviedescription."|".$moviecast."\n");

write_file('FILE1', join '|', $NameText, $moviedescription, "$moviecast\n";

i am a newbie here with perl and cgi..so any help will highly
appreciate!!!!!!!!


Have you seen the Perl FAQs that deal with CGI and HTML?


perldoc -q CGI

Where can I learn about CGI or Web programming in Perl?

What is the correct form of response from a CGI script?

My CGI script runs from the command line but not the browser. (500
Server Error)

How can I get better error messages from a CGI program?

How do I make sure users can't enter values into a form that cause my
CGI script to do bad things?

How do I decode a CGI form?


perldoc -q HTML

How do I remove HTML from a string?

How do I fetch an HTML file?

How do I automate an HTML form submission?
 
T

Tassilo v. Parseval

Also sprach Tad McClellan:
Don't use the ampersand on function calls unless you know what it
does, and what it does is what you want (it seldom is what you want).

You should always, yes *always*, check the return value from open():

open_file("FILE1", ">>", $filename) or
die "could not open '$filename' $!";

That applies to open(), but what is open_file()?

When looking at this sequence:

&open_file("FILE1",">>",$filename);
write_file('FILE1', join '|', $NameText, $moviedescription,"$moviecast\n";
close FILE1;

I get pain in my stomach. In the first two lines, "FILE1" is used as a
string, while in the last line it is used as a filehandle. This can only
work if the filehandle is created in open_file() through a symbolic
reference or so.

We need to see the code of open_file() and write_file().

Tassilo
 
G

gnari

Tassilo v. Parseval said:
Also sprach Tad McClellan:
When looking at this sequence:

&open_file("FILE1",">>",$filename);
write_file('FILE1', join '|', $NameText, $moviedescription,"$moviecast\n";
close FILE1;

I get pain in my stomach. In the first two lines, "FILE1" is used as a
string, while in the last line it is used as a filehandle. This can only
work if the filehandle is created in open_file() through a symbolic
reference or so.

We need to see the code of open_file() and write_file().

no, I think we actually do not need to see that

I would much rather help the OP with some of his own code.

gnari
 
T

Tassilo v. Parseval

Also sprach gnari:
no, I think we actually do not need to see that

I would much rather help the OP with some of his own code.

There were no use() or require() statements in the code he posted, so I
assume that these are functions defined by him.

Tassilo
 
G

gnari

Tassilo v. Parseval said:
Also sprach gnari:


There were no use() or require() statements in the code he posted, so I
assume that these are functions defined by him.

well,
a) this was obviously not a complete program.
b) the way he said 'modify the code' somehow suggested to me that the code
was felched from the net. (I used the admittedly buggy ESP module for that)
c) if it was his own code, he would have realized that he was not posting
the
most critical part, namely the open_file() and write_file() subs.

I think you give the OP to much benefit of doubt.

gnari
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top