-----Original Message-----
>From: Analysis & Solutions
>Without seeing the script, it'd be hard for us to say. So, post the
>_relevant parts_ of the script to the list.
Here's the code:
<?
// Saving edited data to the file
// Data File : This file need to be writeable
$file_name = "data.txt";
// check to see if submit was pressed
if ($insert && $linenumber) {
// check existence of file
$try = touch($file_name);
if (!$try) {
echo "<p>I'm sorry, but I couldn't open a file!";
exit;
}
$array = file($file_name);
// this is the stuff we get from the form, we insert it into an array
$input = array ($id, $name, $creator, $myreview, $prefix, $directory,
$sort, $comments);
// note that we add a \n (line break) to the end of the string.
$output_line = implode ($input, "|")."\n";
// Now open the file (get a file pointer)
$output_stream = fopen($file_name, "w+");
$counter = 0;
foreach($array as $key => $line) {
if($counter == $linenumber) {
$line = $output_line;
}
$out[] = chop($line);
$counter++;
}
foreach($out as $key => $line) {
$result=fputs($output_stream, $line."\n");
}
// close the file pointer
fclose($output_stream);
// give feedback
if ($result) {
echo "<p>Data has been sucessfully added.\n";
echo "<a href=".$PHP_SELF."?line_num=".$linenumber.">View updated
record</a>";
}
else {
echo "<p>Uhoh. . . the database didn't like that.";
}
}else{
// Viewing data from file in a form
//to read the file use:
$fp2= fopen("data.txt", "r");
$line_cnt=0;
while ($servinfo=fgets($fp2,1024)){
if ($line_cnt == $line_num){
$right_line = $servinfo;
list($id, $name, $creator, $myreview, $prefix, $directory, $sort,
$comments)= explode("|",$right_line);
break;
}
$line_cnt++;
}
fclose($fp2);
?>
<Form name="" method="post" action="<?=$PHP_SELF?>">
<CENTER>
<TABLE cellspacing="0" bgcolor="#FFCC99">
<TR bgcolor="#cc0000"><TD>Racestyle data settings</TD><TD>:)</TD></TR>
<TR><TD align=right>Race ID:</TD>
<TD><input type="text" name="id" size="50" maxlength="50" value="<? echo
$id; ?>"></TD></TR>
<TR><TD align=right height="28" nowrap>Racestyle Name:</TD>
<TD height="28"><input type="text" name="name" size="50" maxlength="50"
value="<? echo $name; ?>"></TD></TR>
<TR><TD align=right>Creator:</TD>
<TD><input type="text" name="creator" size="50" maxlength="50" value="<?
echo $creator; ?>"></TD></TR>
<TR><TD align=right valign="top">MyReview:</TD>
<TD><input type="text" name="myreview" size="50" maxlength="400"
value="<? echo $myreview; ?>"></TD></TR>
<TR><TD align=right>Race Prefix</TD>
<TD><input type="text" name="prefix" size="50" maxlength="50" value="<?
echo $prefix; ?>"></TD></TR>
<TR><TD align=right>Race Directory:</TD>
<TD><input type="text" name="directory" size="50" maxlength="50"
value="<? echo $directory; ?>"></TD></TR>
<TR><TD align=right>Sort:</TD>
<TD><select name="sort">
<option value="ship_names" <? if ($sort=="ship_names") { print("
selected");} ?>>small case</option>
<option value="ship_names_2L" <? if ($sort=="ship_names_2L")
print(" selected");} ?>>Upper Case</option>
</select></TD></TR>
<TR><TD align=right valign="top">Comments:</TD>
<TD><input type="text" name="comments" size="50" maxlength="400"
value="<? echo $comments; ?>"></TD></TR>
</TABLE>
</CENTER>
<P align="center">
<input type="hidden" name="linenumber" value="<? if
!isset($line_num)){ $line_num=0;echo $line_num;}else {echo $line_num;} ?>">
<input type=submit value ="Submit" name="insert">
<input type=reset value ="Reset">
</P>
</FORM>
<?
}
?>
The data.txt file has this format:
5|8|4|2|7|2|ship_names|
2|3|7|2|1|9|ship_names_2L|7
4|3|2|7|5|6|ship_names|3
The default line_num is 0. The other entries - database3.php?line_num=1,
database3.php?line_num=2 etc.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php