Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Populate a form based on dropdown selections.

$
0
0

Hi

 

I have a 'categories' mysql table and a 'subcategories' table. I need to make a form so the site owner can remove subcategories as needed.

I was think of having a form with 2 dropdowns on it, the first to choose the category, the second to choose the subcategory. Then based on that selection another form is filled with the chosen subcategories?

I'm unsure how to go about this though..

 

At the minut I have a form that is populated with all the subcategories, but there is no reference to which category they belong to.

 

This is the file

<form action='subcategoryremoveform.php' method='post' enctype='multipart/form-data' 
name='remove_subcategory_form' id='remove_subcategory_form'>
<input type='submit' name='submit' value='Remove Subcategories' />
   <?php
   include '../inc/connect.php';
   $data = mysql_query("SELECT * FROM subcategories")
   or die(mysql_error());
   while($info = mysql_fetch_array( $data )) { 
      echo "<p>";
      echo "<input type='checkbox' name='check[{$info['subcat_id']}]' />";
      echo $info['subcategory'];
      echo "</span>";
      echo "</p>";
   }
   ?>
</form>
<?php
   include '../inc/connect.php';
   if(isset($_POST['check'])){
   $chk = (array) $_POST['check'];
   $p = implode(',',array_keys($chk)); 
   if ($sql = mysql_query("DELETE FROM subcategories WHERE subcat_id IN ($p)")){
      header( 'Location: subcategoryremoveform.php' );
   }
   else{
      echo 'No subcategories have been removed';
   }
   }
                   ?>

Can anyone offer advice on this?


Viewing all articles
Browse latest Browse all 13200

Trending Articles