include fail

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Zeceer
Forum Contributor
Posts: 136
Joined: Fri Aug 02, 2002 5:10 am
Location: Norway

include fail

Post by Zeceer »

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.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

What about the script doesn't work? Do you get any error messages?

Mac
User avatar
Zeceer
Forum Contributor
Posts: 136
Joined: Fri Aug 02, 2002 5:10 am
Location: Norway

Post by Zeceer »

look her: http://www.jehovasvitner.com/include/admin/

Thats the admin panel. Everything looks fine but after pressing the button to delete a product i ain't getting deleted.

For the webshop take a look here: http://www.jehovasvitner.com/include

There tou can see that it doesn't remove anything. When i not include the slett.php it works perfectly. That you can see here http://www.jehovasvitner.com/include/admin/slett.php

I'm not a jehovas vitnesses, so look away form the adress. Just bought it for fun :-)
Post Reply