Hello World! It's my first post on this forum, hello everybody

I'm working on the small simple voting system. The system is based on php/javascript. I'm getting values from form and I'm sending it to database through php-mysql_query.

I need something like this: http://imageshack.us/photo/my-images/803/97450434.png/

but:

1. I must have option to delete the selected gruop/option (for example if somebody do mistake).
2. There must be an option that you cannot add another group, if you don't add in the previous at least one option.

It must be working for form and post php.


I would be grateful if you help me solve these problems



Code:
<?php
ob_start();
session_start(); // rozpoczecie sesji
require_once('../inc/db.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Dokument bez tytułu</title>
	<script src="js/jquery-1.5.2.min.js" type="text/javascript"></script>
	<script src="js/hideshow.js" type="text/javascript"></script>
	<script src="js/jquery.tablesorter.min.js" type="text/javascript"></script>
	<script type="text/javascript" src="js/jquery.equalHeight.js"></script>
<script type="text/javascript">
var counter_group = 0;
var limit_group = 10;
var counter_option = 0;
var limit_option = 10;

var addInput = function(divName) {
  if (counter_option == limit_option - 1) {
    alert('You cannot add more options.');
  } else {
    counter_option++;
    var newdiv = document.createElement('div');
    newdiv.innerHTML = "<font style='margin-left:50px;'>Option</font> " + (counter_option + 1) + "<input type='text' name='groups[" + counter_group + "][options][]'>";
    document.getElementById(divName).appendChild(newdiv);
  }
}

var addGroup = function(divName) {
  if (counter_group == limit_group - 1) {
    alert('You cannot add more groups.');
  } else {
    counter_group++;
    counter_option = -1;
    var newdiv = document.createElement('div');
    newdiv.innerHTML = "Group " + (counter_group + 1) + "<input type='text' name='groups[" + counter_group + "][name]'>";
    document.getElementById(divName).appendChild(newdiv);
  }
}
</script>
</head>

<body>
<form action="costam.php" method="post">
                <input type="hidden" name="sent" value="true" />
<div id="dynamicInput">
  Group 1
  <br>
  <input type="text" name="groups[0][name]">
  <div id="dynamicInput" style="margin-left:50px;">
    Option 1
    <br>
    <input type="text" name="groups[0][options][]">
  </div>
</div>
<input type="button" value="Add another group" onClick="addGroup('dynamicInput');">
<input type="button" value="Add another option" onClick="addInput('dynamicInput');">
                <input type="submit" value="Add to database" class="alt_btn">
</form>
<?php
if($_POST['sent'])
{
echo 'form sent<br />';
foreach ($_POST['groups'] as $group) {
 	$name = $group['name'];
  	//print_r($options = $group['options']); - this will show options // $name - groups 
	//echo '|asdf|'.$name.'|asdf|';
	$wynik = mysql_query("INSERT INTO `grupa` VALUES('',1,'$name','opis',1,1)") or die("<br /> Error: (" . mysql_errno() . ") " . mysql_error());
	echo 'taka powinna byc grupa'.$name;
	$wynik = mysql_query("SELECT * FROM `grupa` WHERE nazwa = '$name'") or die("<br /> Error: (" . mysql_errno() . ") " . mysql_error());
	if(mysql_num_rows($wynik) > 0) 
			{
				while($r = mysql_fetch_assoc($wynik))
				{
					$id_of_group = $r['id'];
				}
			}
			echo $id_of_group;
			
			$options = $group['options'];
			foreach($options as $k => $v) 
			{
				echo 'key='.$k.'value='.$v;
 			$query = "INSERT INTO `opcje_glosowania` VALUES('','$v',9,'$id_of_group',1)";
      		mysql_query($query)  or die("Twoje QUERY: ".$query."<br /> Error: (" . mysql_errno() . ") " . mysql_error());
			}
}
}
?>
		

</body>
</html>
Database looks similar at:
|====GROUP====|
|------id-----|
|----name----|
|=============|

|====OPTION====|
|------id-----|
|--id_group---| //FK to GROUP.ID
|----name----|
|=============|