CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Help with Error

 



CuzDesign
Deleted

May 29, 2000, 10:43 AM

Post #1 of 4 (599 views)
Help with Error Can't Post

Hello,
I am farily new to Perl but have a question on a program I am working on. I have a form that is used to add information to a flatfile database called cars.dat. The problem I am having is that once the form is submitted I get an "500 Internal Server error" but the program still does everything it is supposed to do but show the confirmation page that the listing has been added. Here is the code I am using to handle the form.

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


#!/usr/bin/perl -w
#
##################################################
# #
# This file copyright 2000 Cuzzart's Web Design #
# #
# This program may not be used without written #
# permission from Cuzzart's Web Design #
# #
# #
##################################################
#
use CGI qw(param);
print "Content-type: text/html\n";

$pic = "camera.gif";


## Get contents of form and set to variables
$stock = param('stock');
$year = param('year');
$make = param('make');
$model = param('model');
$price = param('price');
$color = param('color');
$sedan = param('sedan');
$trans = param('trans');
$miles = param('miles');
$desc = param('des');


## Start setting up options here:

# Your path to where you want your files uploaded.
# Note: NO trailing slash
$basedir = "/home/cuzzart/cuzzart-www/usedhtml/images";

# Do you wish to allow all file types? yes/no (no capital letters)
$allowall = "yes";

# If the above = "no"; then which is the only extention to allow?
# Remember to have the LAST 4 characters i.e. .ext
$theext = ".gif";

$nocamera = "";


################################################
################################################
# DO NOT EDIT OR COPY BELOW THIS LINE #
################################################
################################################


if (param('FILE1') ne "") {
# Call upload sub and upload image to directory
&upload;

# Set variable to use image in database
$image = $newmain;

# Make HTML file for each entry so there are more details
system ("rm /home/cuzzart/cuzzart-www/usedhtml/$stock.html");
open (PRO, ">>/home/cuzzart/cuzzart-www/usedhtml/$stock.html");
print PRO " \n";
print PRO "<html>\n";
print PRO "<head>\n";
print PRO "<title>Used Details</title>\n";
print PRO "</head><body>\n";
print PRO "Stock #: $stock <br>\n";
print PRO "Year: $year <br>\n";
print PRO "Make: $make <br>\n";
print PRO "Model: $model <br>\n";
print PRO "Price: \$$price <br>\n";
print PRO "Color: $color <br>\n";
print PRO "Type: $sedan <br>\n";
print PRO "Trans: $trans <br>\n";
print PRO "Miles: $miles <br>\n";
print PRO "Description: $desc <br>\n";
print PRO "Image: <img src=\"http://cuzzart.com/usedhtml/images/$image\" border=\"0\"> <br>\n";
close PRO;

# Print information from form to cars.dat database
open (OUTPUT, ">> cars.dat");
print OUTPUT $pic, ":", $stock, ":", $year, ":", $make, ":", $model, ":", $price, ":", $color, ":", $sedan, ":", $trans, ":", $miles, ":", $desc, "\n";
close (OUTPUT);
}else {
# Make HTML file for each entry so there are more details

system ("rm /home/cuzzart/cuzzart-www/usedhtml/$stock.html");
open (PRO, ">>/home/cuzzart/cuzzart-www/usedhtml/$stock.html");
print PRO " \n";
print PRO "<html>\n";
print PRO "<head>\n";
print PRO "<title>Used Details</title>\n";
print PRO "</head><body>\n";
print PRO "Stock #: $stock <br>\n";
print PRO "Year: $year <br>\n";
print PRO "Make: $make <br>\n";
print PRO "Model: $model <br>\n";
print PRO "Price: \$$price <br>\n";
print PRO "Color: $color <br>\n";
print PRO "Type: $sedan <br>\n";
print PRO "Trans: $trans <br>\n";
print PRO "Miles: $miles <br>\n";
print PRO "Description: $desc <br>\n";
print PRO "Image: No-Image <br>\n";
close PRO;

# Print information from form to cars.dat database
open (OUTPUT, ">> cars.dat");
print OUTPUT $nocamera, ":", $stock, ":", $year, ":", $make, ":", $model, ":", $price, ":", $color, ":", $sedan, ":", $trans, ":", $miles, ":", $desc, "\n";
close (OUTPUT);
}

# Show confirmation
print "<html><head><title>Confirmation</title></head><body>";
print "<center>";
print "Vehicle has been successfully added to the database.<br>\n";
print "To view the inventory <a href=\"http://cuzzart.com/cgi-bin/used/show.pl\">Click here</a>\n";
print "</center>";
print "</body></html>";

sub upload {
$onnum = 1;

while ($onnum != 11) {
my $req = new CGI;
my $file = $req->param("FILE$onnum");
if ($file ne "") {
my $fileName = $file;
$fileName =~ s!^.*(\\|\/)!!;
$newmain = $fileName;
if ($allowall ne "yes") {
if (lc(substr($newmain,length($newmain) - 4,4)) ne $theext){
$filenotgood = "yes";
}
}
if ($filenotgood ne "yes") {
open (OUTFILE, ">$basedir/$fileName");
print "$basedir/$fileName<br>";
while (my $bytesread = read($file, my $buffer, 1024)) {
print OUTFILE $buffer;
}
close (OUTFILE);
}
}
$onnum++;
}
}

exit;
</pre><HR></BLOCKQUOTE>

Any help would be greatly appreciated.

Thank you,
Ray


perlkid
stranger

May 29, 2000, 2:43 AM

Post #2 of 4 (599 views)
Re: Help with Error [In reply to] Can't Post

 
I think that you might need \n\n intead of \n after the content-type: text/html

I've had that problem a couple of times.

Also, just a tip. You could use print qq~~; instead of print "html";. That way you don't have to escape everything. You just put your html between the ~~.

print qq~
<font sixe="2" face = "verdana,arial,helvetica">This is easy html</font>
~;

perlkid


CuzDesign
Deleted

May 29, 2000, 3:07 AM

Post #3 of 4 (599 views)
Re: Help with Error [In reply to] Can't Post

Thanks for the fast reply!

Not to long after I posted it I seen the
error. Was exactly what you said.

Also thanks for the tip on the print qq~~;

I have used print <<EOF; before just not the
one you mentioned.

Again thanks for your time.

Regards,
Ray


perlkid
stranger

May 29, 2000, 11:17 AM

Post #4 of 4 (599 views)
Re: Help with Error [In reply to] Can't Post

 
Job Well Done Cuz,

perlkid

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives