JREAM Posted August 22, 2008 Share Posted August 22, 2008 Guys ive been stuck on this for a while so im going to ask. I am trying to make a checklist that saves the checks to a file, and ties in the name to the check. This is so that in a checklist i can check a box and if its checked i can make it use a css style in the front end. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <?php $thefile = 'test.txt'; $fp = fopen($thefile, 'r'); if($fp) { $line = 1; echo '<table>'; while (!feof($fp)) { $data = fgets($fp); list ($name, $space_set) = explode('|', $data); echo '<tr>'; echo '<td><input name="'.$name.'" type="checkbox" '; if(preg_match("/1/", $space_set)){ echo "checked"; } else { NULL; } echo '/>', $space_set, '</td>'; echo '<td>', $name, '</b></td>'; echo '</tr>'; fwrite($fp, $name); $line++; } echo '</table>'; $check = $_POST[$name]; if ($check == "on") { echo "ON"; } else {echo 'OFF <br />';} fclose($fp); } else {exit('Error: ' . $thefile);} ?> <input type="submit" value="Submit" /> </form> this is what test.txt looks like page|0 page2|1 page3|0 page4|1 page5|1 page6|0 page7|0 Link to comment https://forums.phpfreaks.com/topic/120938-checkbox-loop-file-write-troubles/ Share on other sites More sharing options...
ratcateme Posted August 22, 2008 Share Posted August 22, 2008 you are trying to write to a file that has been opened for reading only i am not exactly sure but that is the first problem i can see with your script also why do you need $line i don't see it being used anywhere Scott. Link to comment https://forums.phpfreaks.com/topic/120938-checkbox-loop-file-write-troubles/#findComment-623409 Share on other sites More sharing options...
JREAM Posted August 22, 2008 Author Share Posted August 22, 2008 starts with line = 1, then at the bottom it does line++ to count, now that i think about it i dont think i need this Link to comment https://forums.phpfreaks.com/topic/120938-checkbox-loop-file-write-troubles/#findComment-623413 Share on other sites More sharing options...
ratcateme Posted August 22, 2008 Share Posted August 22, 2008 do you get any errors what is the actual problem to me it looks like you should get a error on the fwrite(); Scott. Link to comment https://forums.phpfreaks.com/topic/120938-checkbox-loop-file-write-troubles/#findComment-623416 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.