hello everybody,
The following code is used to delete the articles from a table.well, how i'm doing is.........
1.I'm getting all the list of topics in a list box.Select a topic name and then hit a button to show all the sub-topics.Now select again the sub-topic, hit a button, it shows all the article names related to the sub-topic.
2. Theres a check box after each article name and when the user checks the button, hits the delete button, the article has to be deleted from the table.
3.Everything is working fine except the delete part - It does'nt throw me any error mesg if the query is being failed.
4.Could somebody pls tell me where could be the other possible errors?
Many thanks
<?
// dB Connection details
?>
<?php
// if you have chosen articles to delete
if(isset($_POST['action'])){
$qry3="SELECT ARTICLE_ID FROM articles WHERE SUBTOPIC_ID='".$_POST['SUBTOPIC_ID']."'";
$result_3=mysql_query($qry3) or die(mysql_error());
// begin the query (article_ID=0 is there just to have an initial WHERE clause
$qry4="DELETE FROM articles WHERE ARTICLE_ID=0";
while($row_4=mysql_fetch_row($result_3)){
if(isset($_POST[$row_4->ARTICLE_ID])){
// the checkboxes were named for the article_ID
$qry4 .= "OR ARTICLE_ID=".$row_4->ARTICLE_ID;
// add this article 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($_POST['TOPIC_ID'])){
$qry2="SELECT SUBTOPIC_ID, SUBTOPIC_NAME, TOPIC_ID FROM subtopic WHERE TOPIC_ID='".$_POST['TOPIC_ID']."' ORDER BY SUBTOPIC_NAME";
$result_2=mysql_query($qry2) or die(mysql_error());
}
// if you have chosen a subtopic, get the list of articles
if(isset($_POST['SUBTOPIC_ID'])){
$qry3="SELECT ARTICLE_ID, ARTICLE_NAME, SUBTOPIC_ID FROM articles WHERE SUBTOPIC_ID='".$_POST['SUBTOPIC_ID']."' ORDER BY ARTICLE_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>
<?
// also look into mysql_fetch_row, mysql_fetch_array, and mysql_fetch_assoc
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>
<!--- create the subtopic select box --->
<form name="subtopic_form" action="<?=$PHP_SELF?>" method="post">
<select name="SUBTOPIC_ID">
<option value="">Choose a subtopic</option>
<?
if(isset($_POST['TOPIC_ID'])){
while($row_2=mysql_fetch_object($result_2)){
echo "<option value=\"".$row_2->SUBTOPIC_ID."\">".$row_2->SUBTOPIC_NAME."</option>";
}
}
?>
</select>
<!--- include topic_ID for continuity --->
<input type="hidden" name="TOPIC_ID" value="<?=$_POST['TOPIC_ID']?>">
<input type="submit" value="Set SubTopic">
</form>
<!--- create the list of articles --->
<form name="delete_form" action="<?=$PHP_SELF?>" method="post">
<?
if(isset($_POST['SUBTOPIC_ID'])){
while($row_3=mysql_fetch_object($result_3)){
// articles named for the article_ID (aids in ease of retrieval after submittal
echo "<input type=\"checkbox\" name=\"".$row_3->ARTICLE_ID."\" value=1>".$row_3->ARTICLE_NAME."<BR>";
}
}
?>
<!--- include topic_ID & subtopic_ID for continuity --->
<input type="hidden" name="TOPIC_ID" value="<?=$_POST['TOPIC_ID']?>">
<input type="hidden" name="SUBTOPIC_ID" value="<?=$_POST['SUBTOPIC_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>
</HTML>