|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
I've been writing a script to add records to a seperate text file called "rec.db" this works fine and I can add records to my hearts content. However I have to say I am mightly confused on how to edit or delete a specific record. What i've done is each record is identified by it's own personal ID#, very simple all it does each time a record is added count is incremented by one. This is how I find the exact record, and this works surprisingly well here's the code.
sub Editsearch { $datafile = "rec.db"; &urldecode; $searchstr = $FORM{'name'}; open(INF,$datafile); @mydata = <INF>; close(INF); &htmlhead; print "<font face=Arial,Helvetica,sans-serif><h3>Search Results</font></h3>\n"; @results = grep(/$searchstr/i,@mydata); $found = 0; if ($#results >= 0) { foreach $i (@results) { chomp($i); ($count,$name,$price,$desc,$picloc,$cat,$stock) = split(/\|/,$i); if ($count =~ $searchstr){ print qq~ <form action="db.cgi?editsave" method="POST"> <input type=hidden name=count value=\"$count\"> <table width="638" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="9%" valign="top"><font face="Arial, Helvetica, sans-serif" size="2"><b>Name:</b></font></td> <td width="91%" valign="top"><input type="text" name="name" value=\"$name\"></td> </tr> <tr> <td width="9%" valign="top"><font face="Arial, Helvetica, sans-serif" size="2"><b> <br> Price:</b></font></td> <td width="91%" valign="top"><br><input type="text" name="price" value=$price></td> </tr> <tr> <td width="9%" valign="top"><font face="Arial, Helvetica, sans-serif" size="2"><b> <br> Description:</b></font></td> <td width="91%" valign="top"><br><textarea name="desc">$desc</textarea></td> </tr> <tr> <td width="9%" valign="top"><font face="Arial, Helvetica, sans-serif" size="2"><b> <br> Location of picture:</b></font></td> <td width="91%" valign="top"><br><input type="text" name="picloc" value=$picloc></td> </tr> <tr> <td width="9%" valign="top"><font face="Arial, Helvetica, sans-serif" size="2"><b> <br> Category:</b></font></td> <td width="91%" valign="top"><br><select name="cat"> <option value=\"$cat\" selected>$cat <option value="home">Home <option vlaue="work">Work <option value="car">Car <option value="entertainment">Entertainment <option value="outdoors">Outdoors </select></td> </tr> <tr> <td width="9%" valign="top"><font face="Arial, Helvetica, sans-serif" size="2"><b> <br> Stock status:</b></font></td> <td width="91%" valign="top"><br><select name="stock"> <option value=\"$stock\" selected>$stock <option value="IN">IN <option vlaue="OUT">OUT </select></td> </tr> <tr> <td width="9%" valign="top"><br><input type="submit" value="Submit!"></td> <td width="91%" valign="top"><br><input type="reset"></td> </tr> </table></form><br> ~; $found = 1; } } } else { print "<font face=Arial,Helvetica,sans-serif>No results found.</font><p>\n"; } if ($found == 0){ print "<font face=Arial,Helvetica,sans-serif>No results found.</font><p>\n"; } &htmlfoot; } Thats the search done, now here's the code for the editing I've done so far. This is the part that doesn't work! sub Editrecordsave { open (RECDAT, ">>rec.db") or &dienice("Could not open the file rec.db for output writing."); flock(RECDAT,2); foreach $line(@mydata){ ($count,$name,$price,$desc,$picloc,$cat,$stock) = split(/\|/,$line); if ($FORM{'count'} =~ $count){ print RECDAT "$FORM{'count'}|$FORM{'name'}|"; print RECDAT "$FORM{'price'}|$FORM{'desc'}|"; print RECDAT "$FORM{'picloc'}|$FORM{'cat'}|"; print RECDAT "$FORM{'stock'}\n"; } else { print RECDAT "$line"; } } flock(RECDAT, 8); close (RECDAT); &htmlhead; print "<font face=Tahoma size=2>Your profile has been succesfully edited.</font>\n"; &htmlfoot; } Am I close at all, please someone give me a nice answer to point me in the right direction! |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > Flat File Editing via http |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|