PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
spudmclard
Forum Newbie
Posts: 16 Joined: Thu Oct 27, 2005 3:06 am
Post
by spudmclard » Mon May 15, 2006 9:09 am
Hi can anyone help with this...
What im after is to be able to select several checkboxes and depending upon the selections these are added to a flat text file..
Code Follows
Code: Select all
<?php
$file_name = "test.txt";
$fp = fopen($file_name, "r");
echo "<br><form action='$_SERVER[PHP_SELF]'>";
while($line = fgets($fp))
{
echo "<input name='$line' type='checkbox' value='$line'>$line<br>";
}
echo "<br>";
fclose($fp);
echo "<input type='submit'>";
?>
<HR>
<?
if (isset($_POST['submit'])) {
$name = $_POST['$line'];
$fp = fopen("list.txt", "a");
if(!$fp) {
echo 'Error, the file could not be opened';
exit;
}
fwrite($fp, $name."n");
}
?>
tr0gd0rr
Forum Contributor
Posts: 305 Joined: Thu May 11, 2006 8:58 pm
Location: Utah, USA
Post
by tr0gd0rr » Mon May 15, 2006 9:23 am
Start with a few things, then let us know where exactly you are having trouble.
Code: Select all
echo "<br><form action='$_SERVER[PHP_SELF]'>"; // should literally print "'Array[PHP_SELF]'"
echo "<br><form action=\"{$_SERVER['PHP_SELF']}\">"; // correct
Code: Select all
echo "<input type='submit'>"; // cannot be accessed by $_POST['submit']
echo '<input type="submit" name="submit">'; // correct
Code: Select all
$name = $_POST['$line']; // is looking for the literal string "$line"
$name = $_POST[$line]; // correct
I would suggest a careful read of the following page of the PHP manual:
http://us3.php.net/manual/en/language.types.string.php
PS. Don't forget to close your form tag.
spudmclard
Forum Newbie
Posts: 16 Joined: Thu Oct 27, 2005 3:06 am
Post
by spudmclard » Mon May 15, 2006 9:39 am
Thanks
Ive made the changes.
The problem im having is nothing is being written to the 'list.txt' file. All file permissions are ok, so id appreciate any help.
Thanks