ok, i have been playing with this but have not got anywhere, i have made a test site to get this concept going, here is the add page code, i have not got the checkboxes working so i cannot test the insert, but i applied the code, where have i gone wrong..
<?php require_once('Connections/cnnTest.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "balls_add_form")) {
$insertSQL = sprintf("INSERT INTO balls (ball_name, ball_desc) VALUES (%s, %s)",
GetSQLValueString($_POST['txt_ball_name'], "text"),
GetSQLValueString($_POST['txt_ball_desc'], "text"));
mysql_select_db($database_cnnTest, $cnnTest);
$Result1 = mysql_query($insertSQL, $cnnTest) or die(mysql_error());
//standard dreamweaver insert code above
//my insert for sizes below
foreach ($_POST["size"] as $sizeID) {
$ary = "INSERT INTO balls_sizes (ball_id, size_id VALUES (" . $ball_id . ", '" . $sizeID . "')";
// execute query
mysql_select_db($database_cnnTest, $cnnTest);
$Result2 = mysql_query($ary, $cnnTest) or die(mysql_error());
}
//end of my insert for sizes
$insertGoTo = "index.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
mysql_select_db($database_cnnTest, $cnnTest);
$query_rsSizes = "SELECT * FROM sizes ORDER BY size_name ASC";
$rsSizes = mysql_query($query_rsSizes, $cnnTest) or die(mysql_error());
$row_rsSizes = mysql_fetch_assoc($rsSizes);
$totalRows_rsSizes = mysql_num_rows($rsSizes);
?><!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=iso-8859-1" />
<title>Balls add page</title>
</head>
<body>
<p>Balls add page</p>
<form id="balls_add_form" name="balls_add_form" method="POST" action="<?php echo $editFormAction; ?>">
<table width="80%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>Ball Name </td>
<td><input name="txt_ball_name" type="text" id="txt_ball_name" /></td>
</tr>
<tr>
<td>Ball Desc </td>
<td><input name="txt_ball_desc" type="text" id="txt_ball_desc" /></td>
</tr>
<tr>
<td>Sizes</td>
<td>
<?php
// Assume that the database returns the list of areas
for ($i=0; $i < mysql_num_rows($rsSizes); $i++) {
$row = mysql_fetch_row($rsSizes);
echo "<input type=\"checkbox\" name=\"size[]\" value=\"" . $row[0] . "\">\n";
}
?>
<input type="checkbox" name="checkbox" value="checkbox" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Add Ball" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="balls_add_form">
</form>
</body>
</html>
<?php
mysql_free_result($rsSizes);
?>