Page 1 of 1

In/Out Board problem

Posted: Thu Jun 16, 2005 1:12 pm
by sarbz
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:

Image

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>";
}
?>
It also erases anything that's in my flat file. Any ideas?

Posted: Thu Jun 16, 2005 1:31 pm
by John Cartwright

Code: Select all

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='';
}

echo "<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>";
}
You had quotes around some of your PHP. See if that helps.

Posted: Thu Jun 16, 2005 1:50 pm
by sarbz
Great! Now it's working....kinda.

It's deleting whatever is in my inoutdb.txt file, and replacing it with:

Code: Select all

,Update,Update,
when I check the "in office" box and update

or:

Code: Select all

,Update,
When I leave the box unchecked and update.

Here's what it looks like in IE:

Image