Hi everybody! This is my first post here and I want to salute you all and thank you for the help.
First of all, I am new to php. Second, i have to use php 4.1.2 because my ISP doesn't want to upgrade. There is nothing I can do about...
Anyway, i need to delete unwanted messages from my guestbook, (flat db) and i need some help. I want to use the row number to identify the row to delete but i don't understand how to delete the row and save the file.
Here is the code:
<?
//####################################################### resolve compatibility between php4 and php5
function get_file_contents($filename)
/ Returns the contents of file name passed
/
{
if (!function_exists('file_get_contents'))
{
$fhandle = fopen($filename, "r");
$fcontents = fread($fhandle, filesize($filename));
fclose($fhandle);
}
else
{
$fcontents = file_get_contents($filename);
}
return $fcontents;
}
//########################## from http://www.nutt.net/2006/07/08/file_get_contents-function-for-php-4/
// my code...
$action = 0;
$action = $GET["action"];
$my_rownumber = $GET["rownumber"];
if ($action == 1)
{
$file = 'guestbook.txt';
$lines = explode("\n", get_file_contents($file));
foreach($lines as $num => $val)
{
if ( $my_rownumber == $num )
{
// what i have to do here to delete the $val of the row and save the file?
}
}
}
// future edit entries code...
//if ($action == 2)
//{
//}
// view flat db content without html tags and add links to delete and edit
$file = 'guestbook.txt';
$lines = explode("\n", get_file_contents($file));
foreach($lines as $num => $val)
{
$val = strip_tags($val, '<a><b><br>');
echo '<a href="deleteboardentry.php?rownumber='.$num.'&action=1">DELETE ENTRY n.'.$num.'</a> - <a href="editboardentry.php?rownumber='.$num.'&action=2">EDIT ENTRY n.'.$num.'</a><br>'. $val;
}
?>
Thanks :queasy: