include fail
Posted: Wed Aug 07, 2002 5:33 am
when i'm including this file it doesn't work. I don't know but, could it have something to do that it calles it self? I've tried to split up the script to so i get one form part and one script part but that didn't work.
I have an admin section in a webshop and need this script to get included when the user select so.
<?php
$data_file = '../produkter.php';
if (!empty($HTTP_POST_VARS['is_sent'])) process_form();
print "<form action=\"$HTTP_SERVER_VARS[PHP_SELF]\" method=\"POST\">\n";
$data = file($data_file);
$count = count($data);
$pos = 0; // Index of current item
for ($x = 0; $x < $count; $x++)
{
$data[$x] = trim($data[$x]); // Since file() includes the newlines \n
// Print item & checkbox:
if (!empty($data[$x]))
{
print "<input type=\"checkbox\" name=\"item".$pos++."\">";
print "$data[$x]<br><br>\n";
}
}
print "<input type=\"hidden\" name=\"is_sent\" value=\"1\">\n";
print "<input type=\"submit\" value\"test\">\n";
print "</form>\n";
function process_form()
{
global $data_file;
global $HTTP_POST_VARS;
global $HTTP_SERVER_VARS;
$fp = fopen($data_file, 'r+');
$data = fread($fp, filesize($data_file));
// Get each item:
$data = preg_replace("/[\r\n]+/", "\n", $data);
$array = explode("\n", $data);
ftruncate($fp, 0); // Erase the file
fseek($fp, 0); // Go to start of file
$count = count($array);
$pos = 0; // Index of current item
// Write items NOT selected:
for ($x = 0; $x < $count; $x++)
{
if (!empty($array[$x]) && empty($HTTP_POST_VARS['item'.$pos++]))
{
fwrite($fp, $array[$x]."\n");
}
}
fclose($fp);
// Redirect back to the form:
header("Location: slett.php");
exit();
}
?>
This file is slett.php.
I have an admin section in a webshop and need this script to get included when the user select so.
<?php
$data_file = '../produkter.php';
if (!empty($HTTP_POST_VARS['is_sent'])) process_form();
print "<form action=\"$HTTP_SERVER_VARS[PHP_SELF]\" method=\"POST\">\n";
$data = file($data_file);
$count = count($data);
$pos = 0; // Index of current item
for ($x = 0; $x < $count; $x++)
{
$data[$x] = trim($data[$x]); // Since file() includes the newlines \n
// Print item & checkbox:
if (!empty($data[$x]))
{
print "<input type=\"checkbox\" name=\"item".$pos++."\">";
print "$data[$x]<br><br>\n";
}
}
print "<input type=\"hidden\" name=\"is_sent\" value=\"1\">\n";
print "<input type=\"submit\" value\"test\">\n";
print "</form>\n";
function process_form()
{
global $data_file;
global $HTTP_POST_VARS;
global $HTTP_SERVER_VARS;
$fp = fopen($data_file, 'r+');
$data = fread($fp, filesize($data_file));
// Get each item:
$data = preg_replace("/[\r\n]+/", "\n", $data);
$array = explode("\n", $data);
ftruncate($fp, 0); // Erase the file
fseek($fp, 0); // Go to start of file
$count = count($array);
$pos = 0; // Index of current item
// Write items NOT selected:
for ($x = 0; $x < $count; $x++)
{
if (!empty($array[$x]) && empty($HTTP_POST_VARS['item'.$pos++]))
{
fwrite($fp, $array[$x]."\n");
}
}
fclose($fp);
// Redirect back to the form:
header("Location: slett.php");
exit();
}
?>
This file is slett.php.