Jump to content

Recommended Posts

Hi,

 

Again, stuck with a small matter :) I mean here I have a comments box db file where again each entry is written in one line. NOW the problem is that using the array_diff(); when I try to delete it doesn't delete any thing. It doesn't even change any thing :(

 

Here is the code I am using to delete

 

<?php
session_start();

$admin_pass = "123456";

$admin_login_form = 
"<form method=\"post\" action=\"cb_moderation.php\">
<p align=\"center\"><b> Admin Password : </b><input name=\"admin_pass\" type=\"text\" size=\"10\"></p>
<p align=\"center\"><input name=\"submit\" type=\"submit\" value=\"submit\"></p>
</form>
";

if($_POST["admin_pass"] == $admin_pass)
{
$_SESSION["access"] = "access";
}

if($_SESSION["access"] == access)
{


$db = "commentsdb.txt";

if($_GET["delete"])
{
$entry_remove = file("$db");
foreach($entry_remove as $remove)
{
	if(trim(str_replace("\r\n",'',$remove)) == $_GET["delete"])
		{
		$entry_remove = array_diff($entry_remove,array($remove));
		}
}
$entry_remove = implode("",$entry_remove);
$handle = fopen($db,'w');
fwrite($handle,$entry_remove);
fclose($handle);
echo "<meta http-equiv=\"REFRESH\" content=\"0;URL=cb_moderation.php\">";

}

$entry_remove = file("$db");

foreach($entry_remove as $remove)

{

echo $remove .  "<b><a href='cb_moderation.php?delete=" . $remove . "'>[Delete!]</a></b>";

}echo "<hr><p align=\"right\"><a href=\"cb_moderation.php?do=logout\">Log-Out Now!</a></p>";

}else
	{
	echo $admin_login_form;
	}

	if($_GET["do"] == logout)
	{
	$_SESSION["access"] = "";
	session_destroy();
	}

?>

 

And here is the content of commentsdb.txt file ;

 

<br>Posted by <a href="mailto:1">1</a><br><b>1</b><br>...........................
<br>Posted by <a href="mailto:2">2</a><br><b>2</b><br>...........................
<br>Posted by <a href="mailto:3">3</a><br><b>3</b><br>...........................
<br>Posted by <a href="mailto:4">4</a><br><b>4</b><br>...........................
<br>Posted by <a href="mailto:6">6</a><br><b>6</b><br>...........................
<br>Posted by <a href="mailto:7">7</a><br><b>7</b><br>...........................
<br>Posted by <a href="mailto:8">8</a><br><b>8</b><br>...........................
<br>Posted by <a href="mailto:9">9</a><br><b>9</b><br>...........................
<br>Posted by <a href="mailto:10">10</a><br><b>10</b><br>...........................

 

And When I try to delete any one of them, using code above, It changes nothing :( WHY?

 Is it because it have HTML <br>,<b> and <a href> tags that's why?????

If yes then how can i delete these lines from a database :)

 

Thanks a lot. Badly waiting for help :)

Link to comment
https://forums.phpfreaks.com/topic/106194-html-doesnt-delete-with-array_diff/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.