Many thanks
Here is my code
test page
Code:
<?
include 'testdoggy.php';
error_reporting(E_ALL ^ E_NOTICE);
?>
<!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>Untitled Document</title>
<html>
<script>
function showMe (it, box) {
var vis = (box.checked) ? "block" : "none";
document.getElementById(it).style.display = vis;
}
</script>
</head>
<body>
<form action="test.php" method="post" enctype="multipart/form-data" class="style2"><table width="390" border="0">
<tr>
<td>dog name</td>
<td><input type="text" size="20" maxlength="20" name="dogs" <?php if (isset($_POST['dogs'])) { ?> value="<?php echo $_POST['dogs']; ?>"
<?php } ?>/></td>
</tr>
<tr>
<td><? echo breeds() ?> </td>
<td><div id="div1" style="display:none">
<? echo classes() ?>
</div></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Submit" /></td>
<td></td>
</tr>
<tr>
<td width="182"></td>
<td width="198"> </td>
</tr>
</table>
</form>
</body>
</html>
and my function page is
Code:
<?
include 'includes/db.inc.php';
function breeds(){
$returnstr='';
$query = "select breedsID, breedy from doggybreed order by breedy";
$result = @mysql_query($query);
$ii=0;
while($breeds2=mysql_fetch_assoc($result)){
$returnstr= $returnstr.'<label><input type="checkbox" name="breedsID_'.$ii.'" value="'.$breeds2['breedsID'].'" onclick="showMe(\'div1\', this)" >'.$breeds2['breedy'].'</label><br />';
$ii++;
}
$returnstr= $returnstr.'<input type="hidden" name="breedcount" value="'.$ii.'"/>';
return $returnstr;
}
function classes(){
$returnstr='<select name="class1">';
$query = 'select classID, class from doggyclass order by class';
$result = @mysql_query($query);
while($areas=mysql_fetch_array($result)){
$returnstr= $returnstr.'<option value="'.$areas['classID'].'">'.$areas['class'].'</option>';
}
$returnstr= $returnstr.'</select>';
return $returnstr;
}
if (!isset($_POST['submit']))
{
// Store the information in the database
$query = "insert into doggys (dogs)values ('$_POST[ndogs]')";
mysql_query ($query) or die ('Could not add dog.');
$query="select LAST_INSERT_ID() as id";
$result=mysql_query ($query);
if (mysql_num_rows($result) > 0)
{
$dogID = mysql_fetch_array($result);
$dogID=$dogID['id'];
}
$count=count($breed);
//echo 'count='.$_POST['breedcount'].'--';
for($i=0;$i<$_POST['breedcount'];$i++){
if(isset($_POST['breedsID_'.$i])){
$query= "insert into doggybreedy(dogID,breedsID, classID) values($judgeID, '$_POST[class1]',".$_POST['breedid_'.$i].' );';
mysql_query ($query) or die ('Could not add judge breed.');
}
}
}
?>
The idea is that each dynamically generated checkbox has a dropdown field so that when a user enters a name, selects a checkbox and then selects from the dropdown list, the options are sent to the database
Dave
Bookmarks