schris403
11-06-2007, 02:11 AM
I'm struggling with creating a form which will display the current data from a text file so I can modify it. Basically what I want is a form which will allow me to change,delete and create records that look like this in the file.txt file:
1,yes,yes,no
2,no,no,yes
etc
I have a form that will add them but now I need to update/change and delete records as well. It is:
<?php
if(isset($_POST['add']))
{
$new_entry = $_POST['id'];
$new_entry .= ',' . implode(',',$_POST['option']) . "\n";
echo 'Adding: ' . $new_entry;
// write new entry to file
$handle = fopen('file.txt', 'a'); // open
fwrite($handle, $new_entry); // write
fclose($handle); // close
}
?>
<form action="#" method="post">
<table border="0" cellpadding="5" cellspacing="0">
<tr>
<th colspan="4">Add New</th>
</tr>
<tr>
<th>ID</th>
<th colspan="3">Options</th>
</tr>
<tr>
<td><input type="text" name="id" size="10" /></td>
<td><select name="option[]">
<option value="yes">Yes</option>
<option value="no">No</option>
</select></td>
<td><select name="option[]">
<option value="yes">Yes</option>
<option value="no">No</option>
</select></td>
<td><select name="option[]">
<option value="yes">Yes</option>
<option value="no">No</option>
</select></td>
</tr>
<tr>
<td colspan="4"><input type="submit" name="add" value="Add" /></td>
</tr>
</table>
</form>
Any help would be greatly appreciated.
Thanks a lot!
Chris
1,yes,yes,no
2,no,no,yes
etc
I have a form that will add them but now I need to update/change and delete records as well. It is:
<?php
if(isset($_POST['add']))
{
$new_entry = $_POST['id'];
$new_entry .= ',' . implode(',',$_POST['option']) . "\n";
echo 'Adding: ' . $new_entry;
// write new entry to file
$handle = fopen('file.txt', 'a'); // open
fwrite($handle, $new_entry); // write
fclose($handle); // close
}
?>
<form action="#" method="post">
<table border="0" cellpadding="5" cellspacing="0">
<tr>
<th colspan="4">Add New</th>
</tr>
<tr>
<th>ID</th>
<th colspan="3">Options</th>
</tr>
<tr>
<td><input type="text" name="id" size="10" /></td>
<td><select name="option[]">
<option value="yes">Yes</option>
<option value="no">No</option>
</select></td>
<td><select name="option[]">
<option value="yes">Yes</option>
<option value="no">No</option>
</select></td>
<td><select name="option[]">
<option value="yes">Yes</option>
<option value="no">No</option>
</select></td>
</tr>
<tr>
<td colspan="4"><input type="submit" name="add" value="Add" /></td>
</tr>
</table>
</form>
Any help would be greatly appreciated.
Thanks a lot!
Chris