The last error I get is:
Notice: Undefined variable: connection in /mounted-storage/home3/sub007/sc11537-DNSM/michal/forum/delete.php on line 12
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /mounted-storage/home3/sub007/sc11537-DNSM/michal/forum/delete.php on line 12
Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /mounted-storage/home3/sub007/sc11537-DNSM/michal/forum/delete.php on line 13
What my code suppose to do:
I created a forum with database. For each topic in my forum there can be a response so when I delete a topic from my forum I check if it has kids and if so I delete all the kids too.
I also check if it has a parent and if so I reduce the number of kids from the "parent topic"
My forum works. Now I need to fix the delete page
If anyone can help
I will appreciate it a lot
Thanks
Michal
the code for the "delete.php":
Code: Select all
<?php
error_reporting(E_ALL);
$connection = mysql_connect("mysql2.servage.net", "DBname", "password");
mysql_select_db("DBname", $connection);
//hanle children -delete all children and grandchildren
function children($currentid){
$query="select * from forum1 where parent=" . (int)($currentid) ;
$result_children= mysql_query($query,$connection);
$num=mysql_numrows($result_children);
$i=0;
while ($i < $num){
if (mysql_result($result_children,$i,"children")!=0) children(mysql_result($result_children,$i,"id")); //handle children
if (mysql_result($result_children,$i,"parent")!="") parent(mysql_result($result_children,$i,"parent")); // hadle parent
$query = "delete from forum1 where id = " . (int)( mysql_result($result_children,$i,"id") ) ;
mysql_query($query) or die(mysql_error());
$i++;
}
}
//handle parent- decrease number of children
function parent($currentid){
$query="UPDATE forum1 SET children=children-1 WHERE id=" . (int)($currentid);
mysql_query($query) or die(mysql_error());
}
$query="select * from forum1" ;
$result= mysql_query($query,$connection) or die(mysql_error());
$num=mysql_numrows($result);
$i=0;
while ($i < $num) {
$resultid=mysql_result($result,$i,"id");
if (isset($_REQUEST["checkboxid".$resultid ])) {
if (mysql_result($result,$i,"children")!=0) children(mysql_result($result,$i,"id")); // if it has childrens - handle childrens
if (mysql_result($result,$i,"parent")!="") parent(mysql_result($result,$i,"parent")); //if it has a parent -handle parent
$query = "delete from forum1 where id=" . (int)( mysql_result($result,$i,"id") );
mysql_query($query,$connection) or die(mysql_error());
}
$i++;
}
//mysql_close();
//header("Location: cleanforum.php");
//exit;
?><head>
<title>Delete</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1255">
</head>
<body>
</body>
</html>