
CuzDesign
Deleted
Jun 29, 2000, 12:34 PM
Post #5 of 7
(540 views)
|
|
Re: Help with Testing field in database!
[In reply to]
|
Can't Post
|
|
Jasmine, Thank you again for your fast reply. I tried changing it to make it lower case using the lc and still get the same problem. Let me explain it better as to where everything is coming from. I am getting the input from a text field in a form like so: $stock = param('stock'); as well as the other fields that are in the form. What I have is 2 subs one for testing one field to see which database to write to. Here is the entire program as it sits now. Like so: <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> #!/usr/local/bin/perl use CGI qw(param); print "Content-type: text/html\n\n"; #################################### ##### Start User configuration ##### #################################### # Name of domestic database file for cars $domestic = "domestic.dat"; # Name of domestic database file for cars $imports = "imports.dat"; # Name of domestic database file for cars $trucks = "trucks.dat"; # Your path to where you want your files uploaded. # Note: NO trailing slash $upload = '/home/cuzzart/cuzzart-www/usedhtml/images'; # Path to details html files $path = '/home/cuzzart/cuzzart-www/usedhtml'; # Do you wish to allow all file types? yes/no (no capital letters) $allowall = "no"; # If the above = "no"; then which is the only extention to allow? # Remember to have the LAST 4 characters i.e. .ext $theext = ".gif"; # Add picture camera.gif to database if image uploaded $pic = "camera.gif"; # If added file has no image set database to no pic $nocamera = "none"; # Name and location of header.html file $head = "html.header"; # Name and location of footer.html file $foot = "html.footer"; #################################### ##### End User configuration ##### #################################### ####################################################################### #################### DO NOT EDIT BELOW THIS LINE ###################### ####################################################################### # Set Header local $/; open(HEAD, "<$head") or die $!; $header = <HEAD>; close HEAD; # Set footer local $/; open(FOOT, "<$foot") or die $!; $footer = <FOOT>; close FOOT; ## 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'); $type = param('type'); $desc = param('des'); # Test to see what the action is and do sub accordingly $action = param('action'); if ($action eq ''){&form} elsif ($action eq 'main'){&main} elsif ($action eq 'auth'){&auth} elsif ($action eq 'show'){&show} elsif ($action eq 'add'){&add} sub form { print $header; print <<EOF; <tr> <td><img src="http://cuzzart.com/used/images/add_vehform_top.gif" width="525" height="30" border="0"></td> </tr> <tr> <td bgcolor="#C0C0C0"><FONT SIZE="-1" FACE="verdana, arial, helvetica">Use the form below to add a vehicle to your inventory database. Vehicles added will be visable immediately. If you do not have an image leave the image field <b>BLANK</b>.</font></td> </tr> </table> <table width="525" cellspacing="0" cellpadding="4" border="0" bgcolor="#C0C0C0"> <tr><form action="used.pl" method="post" ENCTYPE="multipart/form-data"> <input type=\"hidden\" name=\"action\" value=\"add\"> <td><FONT SIZE="-1" FACE="verdana, arial, helvetica"><b>Stock #:</b></font></td> <td align="left"><input type="text" name="stock" size="25" maxlength="45"></td> </tr> <tr> <td><FONT SIZE="-1" FACE="verdana, arial, helvetica"><b>Year:</b></font></td> <td align="left"><input type="text" name="year" size="25" maxlength="55"></td> </tr> <tr> <td><FONT SIZE="-1" FACE="verdana, arial, helvetica"><b>Make:</b></font></td> <td align="left"><input type="text" name="make" size="25" maxlength="35"></td> </tr> <tr> <td><FONT SIZE="-1" FACE="verdana, arial, helvetica"><b>Model:</b></font></td> <td align="left"><input type="text" name="model" size="25" maxlength="35"></td> </tr> <tr> <td><FONT SIZE="-1" FACE="verdana, arial, helvetica"><b>Price:</b></font></td> <td align="left"><input type="text" name="price" size="25" maxlength="55"></td> </tr> <tr> <td colspan=2 bgcolor="#000000"><FONT SIZE="-1" FACE="verdana, arial, helvetica" color="#FFFFFF"><b>Vehicle Details</b></font></td> </tr> <tr> <td><FONT SIZE="-1" FACE="verdana, arial, helvetica"><b>Color:</b></font></td> <td align="left"><input type="text" name="color" size="25" maxlength="45"></td> </tr> <tr> <td><FONT SIZE="-1" FACE="verdana, arial, helvetica"><b>Sedan/Coupe:</b></font></td> <td align="left"><input type="text" name="sedan" size="25" maxlength="55"></td> </tr> <tr> <td><FONT SIZE="-1" FACE="verdana, arial, helvetica"><b>Transmission:</b></font></td> <td align="left"><input type="text" name="trans" size="25" maxlength="35"></td> </tr> <tr> <td><FONT SIZE="-1" FACE="verdana, arial, helvetica"><b>Miles:</b></font></td> <td align="left"><input type="text" name="miles" size="15" maxlength="15"></td> </tr> <tr> <td><FONT SIZE="-1" FACE="verdana, arial, helvetica"><b>Type:</b></font></td> <td align="left"><select name="type" size="1"> <option value="dom" SELECTED>Domestic </option> <option value="imp">Import </option> <option value="tru">Truck </option> </select></td> </tr> <tr> <td><FONT SIZE="-1" FACE="verdana, arial, helvetica"><b>Description:</b></font></td> <td align="left"><textarea cols="35" rows="5" name="des"></textarea></td> </tr> <tr> <td><FONT SIZE="-1" FACE="verdana, arial, helvetica"><b>Image:</b></font></td> <td align="left"><input type="file" name="FILE1" size="25"><br><FONT SIZE="-1" FACE="verdana, arial, helvetica"><i>(If you do not have an image leave this blank)</i></font></td> </tr> <tr> <td align="right"><input type="Reset"></td> <td align="center"><input type="submit" value="Add To Inventory"></td> </tr> </form> </table> <table width="416" cellspacing="0" cellpadding="0" border="0"> <tr> <td><img src="http://cuzzart.com/used/images/add_vehform_bottom.gif" width="525" height="28" border="0"></td> </tr> <tr> <td align="center"><br><a href="Javascript:history.back()">Back</a></td> </tr> EOF print $footer; } # Add information to Database once form has been filled in sub add { $stock = param('stock'); # If Truck add vehicle to truck database if ($type eq "tru"){&trucks;} elsif ($type eq "dom"){&domestic;} elsif ($type eq "imp"){&imports;} } # Add to Trucks database sub trucks{ $good = 0; open (DATA,"<$trucks") or die "Couldn't open $trucks $!\n"; while (<DATA> ){ chomp; my $dbstock = (split(/:/))[1]; # 1. if (lc($dbstock) eq lc($stock)){ # 2 $good = 1; last; }else{ print "[$dbstock] ne [$stock]<BR>\n"; } } close (DATA); if ($good == 1) { print "Stock number already added<br>\n"; print "<a href=\"Javascript:history.back()\">Click here</a> to go back and try a new Stock number\n"; }else{ open (OUTPUT, ">> $trucks"); print OUTPUT join(":", $nocamera, $stock, $year, $make, $model, $price, $color, $sedan, $trans, $miles, $desc); print OUTPUT "\n"; close (OUTPUT); print "Vehicle added succesfully\n"; } } # Add to domestic database sub domestic{ $good = 0; open (DATA,"<$domestic") or die "Couldn't open $domestic $!\n"; while (<DATA> ){ chomp; my $dbstock = (split(/:/))[1]; # 1. if (lc($dbstock) eq lc($stock)){ # 2 $good = 1; last; }else{ print "[$dbstock] ne [$stock]<BR>\n"; } } close (DATA); if ($good == 1) { print "Stock number already added<br>\n"; print "<a href=\"Javascript:history.back()\">Click here</a> to go back and try a new Stock number\n"; }else{ open (OUTPUT, ">> $domestic"); print OUTPUT join(":", $nocamera, $stock, $year, $make, $model, $price, $color, $sedan, $trans, $miles, $desc); print OUTPUT "\n"; close (OUTPUT); print "Vehicle added succesfully\n"; } } # Add to Imports database sub imports{ $good = 0; open (DATA,"<$imports") or die "Couldn't open $imports $!\n"; while (<DATA> ){ chomp; my $dbstock = (split(/:/))[1]; # 1. if (lc($dbstock) eq lc($stock)){ # 2 $good = 1; last; }else{ print "[$dbstock] ne [$stock]<BR>\n"; } } close (DATA); if ($good == 1) { print "Stock number already added<br>\n"; print "<a href=\"Javascript:history.back()\">Click here</a> to go back and try a new Stock number\n"; }else{ open (OUTPUT, ">> $imports"); print OUTPUT join(":", $nocamera, $stock, $year, $make, $model, $price, $color, $sedan, $trans, $miles, $desc); print OUTPUT "\n"; close (OUTPUT); print "Vehicle added succesfully\n"; } } </pre><HR></BLOCKQUOTE> Here is what I am getting when I added that else staement you put in: <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> [G12345] ne [R12345] [] ne [R12345] Vehicle added succesfully </pre><HR></BLOCKQUOTE> Which from looking at it tells me it is stopping after it finds a match but adds as well as when it finds a match. Hope this helps explain it better of what I am trying to do and maybe help find the problem. Thank you for all your help. Thank you, Ray [This message has been edited by CuzDesign (edited 06-29-2000).]
|