Hello,
I would save the state of checkboxes that them clicked on(checked) or clicked off(unchecked) and save that in a txt-file. The txt-file is quasi the database. And of course the state has to readout of it, too.
For now, only the save-function works, the readout not.
My Code:
index.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test</title>
</head>
<body>
<fieldset>
<legend>Form</legend>
<?php
/* Save and readout of the txt-file */
if (isset($_POST['check'])) {
reset($_POST['check']);
unlink("log.txt");
for ($i=0; $i<count($_POST['check']);$i++) {
//echo "<br />value $i = ".$_POST['check'][$i];
$dateiname = "log.txt";
$handler = fOpen($dateiname , "a+");
fWrite($handler , "value $i = ".$_POST['check'][$i] . "\n");
fClose($handler);
}
}
//Formularangaben einlesen
foreach (file("log.txt") as $zeile) {
if (strpos($zeile, " = ")) {
list($variable, $value) = explode(" = ", $zeile);
$$variable = chop($value);
if($value!="") {
$checked = checked;
}
}
}
// Formular (Formularangaben ausgeben)
echo '<form action="' . $_SERVER["SCRIPT_NAME"] . '" method="post">
<table border="1" align="center">
<tr>
<td></td>
<td><br><br>12.02.12<br><br><br></font></td>
<td><br><br>13.02.12<br><br><br></font></td>
<td><br><br>14.02.12<br><br><br></font></td>
<td><br><br>15.02.12<br><br><br></font></td>
<td><br><br>16.02.12<br><br><br></font></td>
</tr>
<tr align="center">
<td>Hans</td>
<td><input type="checkbox" name="check[]" value="1.1" '.$checked.'/></td>
<td><input type="checkbox" name="check[]" value="1.2" '.$checked.'/></td>
<td><input type="checkbox" name="check[]" value="1.3" '.$checked.'/></td>
<td><input type="checkbox" name="check[]" value="1.4" '.$checked.'/></td>
<td><input type="checkbox" name="check[]" value="1.5" '.$checked.'/></td>
</tr>
</table>
<center><p> <input type="submit" value="Speichern"> </p></center>
</form>';
?>
</fieldset>
</body>
</html>
I would be glad for help and approach.
regards
Carl88