Jump to content

Checkbox, loop file write, troubles


JREAM

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.