Google Answers Logo
View Question
 
Q: PHP script change - add text box information to text file ( No Answer,   0 Comments )
Question  
Subject: PHP script change - add text box information to text file
Category: Computers > Programming
Asked by: sjw-ga
List Price: $10.00
Posted: 17 May 2005 20:34 PDT
Expires: 16 Jun 2005 20:34 PDT
Question ID: 522799
In reference to the script below, how can I add a text box and have
what is entered into the text box be transferred (moved) to
issues_deleted.txt file?

<table>
<tr>
<td>
<?php
$path_to_dir = 'issues'; // path to text file
$file_contents = file("$path_to_dir/issues.txt"); // the file
$file_contents_deleted = file("$path_to_dir/issues_deleted.txt"); // the file
// [ DELETE ROUTINE ]
if($_POST['action'] == "delete"){ // delete triggered
$arrToDelete = $_POST['todelete']; // assign checked items array to var
if($arrToDelete != "") { // if the array isnt open proceed
foreach($arrToDelete as $key => $value) { // assign a key and value to
each checked item
#$file_contents_deleted[count($file_contents_deleted)] = $file_contents[$key];
$file_contents_deleted[] = $file_contents[$key];
array_splice($file_contents, $key, 1, "");// assign null value to each
checked item in file_contents array
print("Deleted <b>$value</b><br>");
}
$sizeof = count($file_contents_deleted); // count updated file_contents array
if($filehandle = fopen("$path_to_dir/issues_deleted.txt", "w")){ //
open the file for writing
for($y = 0; $y < $sizeof; $y++){ // loop through the new file_contents array
if($file_contents_deleted){ 
fputs($filehandle, $file_contents_deleted[$y]); // write the new
file_contents array to the file
}
}
fclose($filehandle); // close the file
}
$sizeof = count($file_contents); // count updated file_contents array
if($filehandle = fopen("$path_to_dir/issues.txt", "w")){ // open the
file for writing
for($y = 0; $y < $sizeof; $y++){ // loop through the new file_contents array
if($file_contents){ 
fputs($filehandle, $file_contents[$y]); // write the new file_contents
array to the file
}
}
fclose($filehandle); // close the file
}
}
}
?>
<?php     // [ READ & OUTPUT FILE CONTENTS ]     ?>
<!-- The Form & Table -->
<form method="POST" action="<?php $PHP_SELF ?>" style="margin:0;">
<input type="hidden" name="action" value="delete">
<table border="1">
<tr>
<td class="spectable"><b><h2><a href="<?php $PHP_SELF
?>?sort=user">User</a></td><td
class="spectable"><b><h2><a href="<?php $PHP_SELF ?>?sort=name">Name</a></td><td
class="spectable"><b><h2><a href="<?php $PHP_SELF ?>?sort=issue">Issue</a></td><td
class="spectable"><b><h2><a href="<?php $PHP_SELF
?>?sort=description">Description</a></td><td
class="spectable"><b><h2><a href="<?php $PHP_SELF
?>?sort=email">Email</a></td><td class="spectable"><b><h2><a
href="<?php $PHP_SELF ?>?sort=timesent">Time Sent</a></td><td
class="spectable"><b><h2><a href="<?php $PHP_SELF
?>?sort=date">Date</a></td><td
class="spectable"><b><h2>Issue Resolved</td>
</tr>
<?php
$file_contents = file("$path_to_dir/issues.txt"); // the file
foreach($file_contents as $key=>$value){ // assign a key to each line in the file
if($file_contents[$key] != ""){
$entry = explode("\t", $file_contents[$key]); // break out each
delimeter - tab in this case
$entries[]=array('user'=>$entry[0], 'name'=>$entry[1],
'issue'=>$entry[2], 'description'=>$entry[3], 'email'=>$entry[4],
'timesent'=>$entry[5], 'date'=>$entry[6], 'key'=>$key,
'value'=>$value);
#print("<tr>
#<td class=spectable><b><h3><center>".$entry[0]."</td>
#<td class=spectable><b><h3><center>".$entry[1]."</td>
#<td class=spectable><b><h3><center>".$entry[2]."</td>
#<td class=spectable><b><h3><center>".$entry[3]."</td>
#<td class=spectable><b><h3><center>".$entry[4]."</td>
#<td class=spectable><b><h3><center>".$entry[5]."</td>
#<td class=spectable><b><h3><center>".$entry[6]."</td>
#<td class=spectable><b><h3><center><input type=checkbox
name=todelete[$key] value=$value></center></td>
#</tr>");
}
}
if ($entries) {
foreach ($entries as $key => $row) {
$user[$key]  = $row['user'];
$name[$key] = $row['name'];
$issue[$key] = $row['issue'];
$description[$key] = $row['description'];
$email[$key] = $row['email'];
$timesent[$key] = $row['timesent'];
$date[$key] = $row['date'];
}
switch ($sort) {
case "user": array_multisort($user, SORT_ASC, $entries); break;
case "name": array_multisort($name, SORT_ASC, $entries); break;
case "issue": array_multisort($issue, SORT_ASC, $entries); break;
case "description": array_multisort($description, SORT_ASC, $entries); break;
case "email": array_multisort($email, SORT_ASC, $entries); break;
case "timesent": array_multisort($timesent, SORT_ASC, $entries); break;
case "date": array_multisort($date, SORT_ASC, $entries); break;
}
}
for($i=0; $i<sizeof($entries); $i++) {
print("<tr>
<td class=spectable><b><h3><center>".$entries[$i]['user']."</td>
<td class=spectable><b><h3><center>".$entries[$i]['name']."</td>
<td class=spectable><b><h3><center>".$entries[$i]['issue']."</td>
<td class=spectable><b><h3><center>".$entries[$i]['description']."</td>
<td class=spectable><b><h3><center>".$entries[$i]['email']."</td>
<td class=spectable><b><h3><center>".$entries[$i]['timesent']."</td>
<td class=spectable><b><h3><center>".$entries[$i]['date']."</td>
<td class=spectable><b><h3><center><input type=checkbox
name=todelete[".$entries[$i]['key']."]
value=".$entries[$i]['value']."></center></td>
</tr>");
}
?>
<tr>
<td colspan="8" align="center" class="spectable"><input type="submit"
value="Remove Resolved Issue"></td>
</tr>
</table>
</form>
</td>
</table>
<br><br><br>
Answer  
There is no answer at this time.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy