In/Out Board problem
Posted: Thu Jun 16, 2005 1:12 pm
Hello,
I have a simple in/out baord that someone is helping me with, and I'm getting some errors. When it's run, I get this:

Here's the code:
It also erases anything that's in my flat file. Any ideas?
I have a simple in/out baord that someone is helping me with, and I'm getting some errors. When it's run, I get this:

Here's the code:
Code: Select all
<?
$ff="/users/wensco/sites/inout/inoutdb.txt";
if (isset($_POST)) {
foreach ($_POST as $name=>$value) {
if ($value=="on" || $value=="off") {
$somecontent.= $value . "\n";
}
else {
$somecontent.= $value . ",";
}
}
$handle=fopen($ff, "w+");
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($ff)";
exit;
}
fclose($ff);
}
display_file($ff);
//Functions------------------------
function display_file($file){
//Put file into $contents
$contents = file_get_contents($file);
//Split each file row into an array value
$contents=explode("\n",$contents);
// You could try using $PHP_SELF instead of $_SERVER['PHP_SELF'], but if the page is only being accessed through IE you can just leave it.
echo "<form action='".$_SERVER['PHP_SELF']."' method='POST'><table>";
$i=0;
foreach($contents as $item){
$i+=1;
$person=explode(",",$item);
echo "
<tr><td><input type='hidden' name='$i' value='$person[0]'>$person[0]</td><td>
if ($person[1]=='on') {
$mark='CHECKED';
}
else {
$mark='';
}
<input type='checkbox' name='".$i."c' value='$person[1]' $mark>In office?</td></tr>";
}
// Put the Update button under it all
echo "<tr><td><input type='submit' name='Submit' value='Update'></td></tr>";
echo "</table></form>";
}
?>