PDA

View Full Version : DW PHP mySQL - Menu/List Multiple Selection INSERT to Multiple Rows


Eric1977
10-01-2012, 04:48 AM
Greetings,

I am attempting to use a Dreamweaver Menu/List that multiple items can be selected from. The goal is to input each selection along with course id number and a 'Y' into individual rows of a mySQL database. The code below allows for only one row to be inputted into the database. The entire code for the page is listed below (probably more info below than anyone would need...)

Any assistance would be much appreciated! :confused:





<?php require_once('../../../../../Connections/connUser.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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"] == "form1")) {
$insertSQL = sprintf("INSERT INTO orgcourserights (course_id, org_id, org_rights) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['hiddenFieldCourseID'], "int"),
GetSQLValueString($_POST['selectOrganization'], "int"),
GetSQLValueString($_POST['hiddenFieldYes'], "text"));

mysql_select_db($database_connUser, $connUser);
$Result1 = mysql_query($insertSQL, $connUser) or die(mysql_error());

$insertGoTo = "CourseOrganizationRights.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}

$colname_rsCourseInfo = "-1";
if (isset($_GET['id'])) {
$colname_rsCourseInfo = $_GET['id'];
}
mysql_select_db($database_connUser, $connUser);
$query_rsCourseInfo = sprintf("SELECT * FROM course WHERE course_id = %s", GetSQLValueString($colname_rsCourseInfo, "int"));
$rsCourseInfo = mysql_query($query_rsCourseInfo, $connUser) or die(mysql_error());
$row_rsCourseInfo = mysql_fetch_assoc($rsCourseInfo);
$totalRows_rsCourseInfo = mysql_num_rows($rsCourseInfo);

mysql_select_db($database_connUser, $connUser);
$query_rs_AllOrgs = "SELECT * FROM orgid ORDER BY org_id DESC";
$rs_AllOrgs = mysql_query($query_rs_AllOrgs, $connUser) or die(mysql_error());
$row_rs_AllOrgs = mysql_fetch_assoc($rs_AllOrgs);
$totalRows_rs_AllOrgs = mysql_num_rows($rs_AllOrgs);
?>
<!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>Untitled</title>
<script type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>
<style type="text/css">
<!--
.style4 {
color: #5add45;
font-weight: bold;
font-size: 24pt;
}
.style6 {color: #5add45}
.style7 {
color: #494949;
font-size: 16px;
}
.style8 {font-weight: bold}
.style10 {color: #939895; font-weight: bold; }
.style13 {font-size: larger}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
a:active {
text-decoration: none;
}
.style10 {
font-weight: normal;
}
.style10 {
font-weight: bold;
}
-->
</style>
<meta name="Keywords" content="
" />
</head>

<body>
<table width="1000" border="0" align="left" class="style7"><!--DWLayoutTable-->
<tr>
<td width="125" height="176" align="left" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
<td colspan="3" rowspan="2" align="left" valign="top"><table width="100%" height="56" border="0">
<tr>
<td width="196" height="52" align="center" class="style4"><table width="716" border="0">
<tr>
<td width="710" height="141" align="left" valign="top" class="style7"><p class="style4">Select Organizations</p>
<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
<p>
<?php
/* Set Variables The code below gets the variable passed through the URL. In this case it is 'id' that it is getting, and it is assigning it to variable $theID
*/

$theID=$_GET['id'];

/*
ER 9/18/12
The "hiddenFieldCourseID below is set to $theID which is set above this comment. This is used so that the hidden field can be entered into the coursequiz mysql table into the course_id field
*/
?>
<input name="hiddenFieldCourseID" type="hidden" id="hiddenFieldCourseID" value="<?php echo $theID; ?>" />


<?php
/* The variable setting below is to set $yes to 'Y' so that it can be added to a hidden field for entry into the Menu/List
*/
$yes='Y';
?>





<input name="hiddenFieldYes" type="hidden" id="hiddenFieldYes" value="<?php echo $yes; ?>" />
</p>
<table width="100%" border="0" cellpadding="0" cellspacing="0" id="TrainingSummaryInfo">
<tr>
<td width="20%">Course ID</td>
<td width="71%"><?php echo $row_rsCourseInfo['course_id']; ?></td>
<td width="9%">&nbsp;</td>
</tr>
<tr>
<td>Course Name</td>
<td><?php echo $row_rsCourseInfo['course_name']; ?></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Regulation</td>
<td><?php echo $row_rsCourseInfo['regulation']; ?></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Subject/Category</td>
<td><?php echo $row_rsCourseInfo['subject']; ?></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>File Name .swf</td>
<td><?php echo $row_rsCourseInfo['filename']; ?></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
<p>Select Organizations Authorized for this Course. (ctrl for multiple) </p>
<p>
<select name="selectOrganization" size="25" multiple="multiple" id="selectOrganization">
<?php
do {
?>
<option value="<?php echo $row_rs_AllOrgs['org_id']?>"<?php if (!(strcmp($row_rs_AllOrgs['org_id'], $yes))) {echo "selected=\"selected\"";} ?>><?php echo $row_rs_AllOrgs['org_name']?></option>
<?php
} while ($row_rs_AllOrgs = mysql_fetch_assoc($rs_AllOrgs));
$rows = mysql_num_rows($rs_AllOrgs);
if($rows > 0) {
mysql_data_seek($rs_AllOrgs, 0);
$row_rs_AllOrgs = mysql_fetch_assoc($rs_AllOrgs);
}
?>
</select>
</p>
<p>
<input type="submit" name="Submit" id="Submit" value="Submit" />
</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<input type="hidden" name="MM_insert" value="form1" />
</form>
<p>&nbsp;</p></td>

</table>
</body>
</html>
<?php
mysql_free_result($rsCourseInfo);

mysql_free_result($rs_AllOrgs);
?>