i made this little script from a tutorial but somehow the edit section does something wrong… and i juist cant find anything worng… can anyone maybe seee whats wrong with this?
<?
$db = "nieuws_db.txt";
$pass = "test";
$tb_area = "";
if($action == "edit" && isset($HTTP_POST_VARS['password'])) {
if($HTTP_POST_VARS['password'] == $pass) {
$line = $HTTP_POST_VARS['date'] . "|" . $HTTP_POST_VARS['name'];
$line .= "|" . $HTTP_POST_VARS['news'];
$line = str_replace("
","<BR>",$line);
$line .= "
";
$data = file($db);
$data[$id] = $line;
reset($data);
$fp = fopen($db,'w');
foreach($data as $element) {
fwrite($fp, $element);
}
fclose($fp);
echo "Item Edited!<BR><BR>
";
echo "<a href=\"$PHP_SELF\">Go Back</a>
";
exit;
} else {
echo "<font class=\"error\">FOUT! paswoord!
";
exit;
}
}
if($action == "edit") {
$data = file($db);
$element = trim($data[$id]);
$pieces = explode("|", $element);
$news = str_replace("<BR>","
",$pieces[4]);
echo "<FORM ACTION=\"$PHP_SELF?action=edit\" METHOD=\"POST\" NAME=\"editform\">
";
//* Nieuws "EDIT VIEW" tabel *//
echo "<font class=\"error\">U gaat een item wijzigen, verander uw tekst, voer uw paswoord in en klik op de knop..!<BR><BR>
";
echo "<FORM ACTION=\"$PHP_SELF?action=delete\" METHOD=\"POST\" NAME=\"deleteform\">
";
echo "<table width=\"400\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\">";
echo "<tr>";
echo "<font class=\"uitleg_kop\">Kop tekst wijzigen:<br><td colspan=\"3\"><INPUT TYPE=\"text\" SIZE=\"65\" NAME=\"name\" value=\"". $pieces[2] ."\"></td>";
echo "</tr>";
echo "<td colspan=\"2\" valign=\"top\" >";
echo "<table width=\"400\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\">";
echo "<tr>";
echo "<td>";
//* plaatje verwijderen of wijzigen *//
if($pieces[3] != '') {
echo "<font class=\"uitleg_kop\">Plaatje wijzigen:<br><INPUT TYPE=\"text\" SIZE=\"65\" NAME=\"name\" value=\"". $pieces[3] . "\"><BR><br>
</td>";
}else{
echo "</td>";
}
echo "</tr>";
echo "</table>";
echo "<TEXTAREA NAME=\"news\" COLS=\"80\" ROWS=\"10\">".$news."</TEXTAREA><BR><BR>
</td>";
echo "<tr>";
echo "</tr>";
echo "<tr>";
echo "<td colspan=\"3\" align=\"right\"><font class=\"news\">Ingevoer op:</font> <font class=\"news_datum\">".$pieces[0]."
</td>";
echo "</tr>";
echo "</table>";
//* Paswoord check *//
echo "Paswoord:<BR>
";
echo "<INPUT TYPE=\"password\" SIZE=\"30\" NAME=\"password\"><BR>
";
echo "<INPUT TYPE=\"hidden\" NAME=\"id\" VALUE=\"$id\">
";
echo "<INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Wijzig\"><BR>
";
echo "</FORM>
";
exit;
}
if($action == "delete" && isset($HTTP_POST_VARS['password'])) {
if($HTTP_POST_VARS['password'] == $pass) {
$data = file($db);
array_splice($data,$id,1);
$fp = fopen($db,'w');
foreach($data as $element) {
fwrite($fp, $element);
}
fclose($fp);
echo "<font class=\"error\">Nieuws item gedelete..!<BR><BR>
";
echo "<a href=\"$PHP_SELF\">Terug..!</a>
";
exit;
} else {
echo "<font class=\"error\">FOUT! paswoord!
";
exit;
}
}
if($action == "delete") {
$data = file($db);
$element = trim($data[$id]);
$pieces = explode("|", $element);
//* Nieuws "DELETE VIEW" tabel *//
echo "<font class=\"error\">U gaat een item deleten, voer uw paswoord in en klik op de knop..!<BR>
";
echo "<FORM ACTION=\"$PHP_SELF?action=delete\" METHOD=\"POST\" NAME=\"deleteform\">
";
echo "<table width=\"400\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\">";
echo "<tr>";
echo "<td colspan=\"3\"><font class=\"news_kop\">". $pieces[2] ."</td>";
echo "</tr>";
echo "<td colspan=\"2\" valign=\"top\" >";
echo "<table width=\"400\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\">";
echo "<tr>";
echo "<td>";
//* plaatje verwijderen of wijzigen *//
if($pieces[3] != '') {
echo "<font class=\"news_datum\">". $pieces[3] . "</td>";
}else{
echo "</td>";
}
echo "</tr>";
echo "</table>";
echo "<font class=\"news\">". $pieces[4] ."</td>";
echo "<tr>";
echo "</tr>";
echo "<tr>";
echo "<td colspan=\"3\" align=\"right\"><font class=\"news\">Ingevoer op: <font class=\"news_datum\">". $pieces[0] ."</td>";
echo "</tr>";
echo "</table>";
//* Paswoord check *//
echo "Paswoord:<BR>
";
echo "<INPUT TYPE=\"password\" SIZE=\"30\" NAME=\"password\"><BR>
";
echo "<INPUT TYPE=\"hidden\" NAME=\"id\" VALUE=\"$id\">
";
echo "<INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Verwijder\"><BR>
";
echo "</FORM>
";
exit;
}
echo "<font class=\"kop\">Laatste ingevoerde nieuws.</font><br><br>
";
$data = file($db);
foreach($data as $key=>$element) {
$element = trim($element);
$pieces = explode("|", $element);
//* Nieuws "VIEW" tabel *//
echo "<table width=\"400\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\">";
echo "<tr>";
echo "<td colspan=\"3\"><font class=\"news_kop\">". $pieces[2] ."</td>";
echo "</tr>";
echo "<td colspan=\"2\" valign=\"top\" >";
echo "<font class=\"news\">". $pieces[4] ."</td>";
echo "<tr>";
echo "</tr>";
echo "<tr>";
echo "<td colspan=\"3\" align=\"right\"><font class=\"news\">Ingevoer op: <font class=\"news_datum\">". $pieces[0] ."</td>";
echo "</tr>";
echo "</table>";
//* EDIT en VERWIJDER knoppen *//
echo "<a href=\"$PHP_SELF?action=delete&id=$key\" class=\"deledit\">Verwijderen</a>
";
echo "<a href=\"$PHP_SELF?action=edit&id=$key\" class=\"deledit\">Wijzigen</a>
";
echo "<br><br><br>
";
}
?>
My best gess is that the edit section of this scrpit screwsup the . Pieces[?] . but i can be wrong…