SunQuest
           Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old March 7th, 2001, 09:07 AM
Paul_Statham Paul_Statham is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Posts: 9 Paul_Statham User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Angry

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!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Flat File Editing via http


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway