hi there,
This is a simple script which I'm using to delete subtopics.
Well, I have Topics and under each topic there are many subtopics and under each subtopic there are many articles.
First, I'm getting all the topic names in a list box, select a topic and then all the subtopics related to that topic are shown.
Now, when i check a subtopic and hit the button delete the subtopics can be deleted.But, before that, I want to check if there are any articles existing under this subtopic which I've chosen for deletion.
So, if there are any articles under this subtopic, i need to show a mesg that they cant be deleted and if there are no articles they can be deleted.
My problem is only to check the last part, that is in-order to check if there are any articles or not.
If i remove the validation part my script works absolutely fine.I've even debugged and it has'nt helped me.
Could somebody please help me out.
Thank you
Heres the script.
<?
include "dbconnection.oam";
?>
<?php
// if you have chosen subtopics to delete
if(isset($HTTP_POST_VARS['action'])){
$qry3="SELECT SUBTOPIC_ID FROM subtopic WHERE SUBTOPIC_ID='".$HTTP_POST_VARS['SUBTOPIC_ID']."'";
$result_3=mysql_query($qry3) or die(mysql_error());
// begin the query
$subtopic_id=$HTTP_POST_VARS['SUBTOPIC_ID'];
echo $subtopic_id;
$result_sub=mysql_query("SELECT * FROM articles WHERE SUBTOPIC_ID='$subtopic_id' ");
$number = mysql_num_rows($result_sub);
// echo("$number");
if (mysql_num_rows($result_sub)>0)
echo "there is more than zero";
else
echo "there are none";
$qry4 = "DELETE FROM subtopic WHERE SUBTOPIC_ID IN('" . implode("','", $HTTP_POST_VARS['to_delete']) . "')";
while($row_4=mysql_fetch_row($result_sub)){
if(isset($HTTP_POST_VARS[$row_4->SUBTOPIC_ID])){
// the checkboxes were named for the subtopic_id
$qry4 .= "OR SUBTOPIC_ID=".$row_4->SUBTOPIC_ID;
// add this subtopic to the query string
}
}
mysql_query($qry4) or die(mysql_error());
}
// get the list of topic names
$qry1="SELECT TOPIC_ID, TOPIC_NAME FROM topic ORDER BY TOPIC_NAME";
$result_1=mysql_query($qry1) or die(mysql_error());
// if you have chosen a topic, get the list of subtopics
if(isset($HTTP_POST_VARS['TOPIC_ID'])){
$qry3="SELECT SUBTOPIC_ID, SUBTOPIC_NAME, TOPIC_ID FROM subtopic WHERE TOPIC_ID='".$HTTP_POST_VARS['TOPIC_ID']."' ORDER BY SUBTOPIC_NAME";
$result_3=mysql_query($qry3) or die(mysql_error());
}
?>
<HTML>
<!--- create the topic select box --->
<form name="topic_form" action="<?=$PHP_SELF?>" method="post">
<select name="TOPIC_ID">
<option value="">Choose a topic</option>
<?
while($row=mysql_fetch_object($result_1)){
echo "<option value=\"".$row->TOPIC_ID."\">".$row->TOPIC_NAME."</option>";
}
?>
</select>
<input type="submit" value="Set Topic">
</form>
<!--- include topic_ID for continuity --->
<input type="hidden" name="TOPIC_ID" value="<?=$HTTP_POST_VARS['TOPIC_ID']?>">
</form>
<!--- create the list of subtopics --->
<form name="delete_form" action="<?=$PHP_SELF?>" method="post">
<?
if(isset($HTTP_POST_VARS['TOPIC_ID'])){
while($row_3=mysql_fetch_object($result_3)){
// subtopics named for the subtopic_id (aids in ease of retrieval after submittal
echo "<input type=\"checkbox\" name=\"to_delete[]\" value=\"".$row_3->SUBTOPIC_ID."\">".$row_3->SUBTOPIC_NAME."<BR>";
}
}
?>
<input type="hidden" name="TOPIC_ID" value="<?=$HTTP_POST_VARS['TOPIC_ID']?>">
<!--- "action" defined so there is a definite switch to determine if things should be deleted --->
<input type="hidden" name="action" value="delete">
<input type="submit" value="Delete">
<FORM>
<INPUT TYPE="Button" VALUE="Back"
onClick="window.location= 'menu.php' ">
</FORM>
</form>
</HTML>