I have a form which generates a list of users from a MySQL table. I want to be able to selct a number of people and then submit the information back to another table. Everything SEEMS to work, but after I check a number of people, I submit the information and check the MySQL table. Only the last person's name and email is saved. I know I have to somehow create an array, but every attempt I make at creating arrays fails. No surprise there! What say you, Master Coders?
<?php require_once('../Connections/ngiportalDB_report_tool.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"] == "form")) {
$insertSQL = sprintf("INSERT INTO int_report_tool (report_title, report_user_name, report_user_email) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['report_title'], "text"),
GetSQLValueString($_POST['report_user_name'], "text"),
GetSQLValueString($_POST['report_user_email'], "text"));
mysql_select_db($database_ngiportalDB_report_tool, $ngiportalDB_report_tool);
$Result1 = mysql_query($insertSQL, $ngiportalDB_report_tool) or die(mysql_error());
}
mysql_select_db($database_ngiportalDB_report_tool, $ngiportalDB_report_tool);
$query_report_tool_assign = "SELECT realName, emailAddress FROM int_members ORDER BY realName ASC";
$report_tool_assign = mysql_query($query_report_tool_assign, $ngiportalDB_report_tool) or die(mysql_error());
$row_report_tool_assign = mysql_fetch_assoc($report_tool_assign);
$totalRows_report_tool_assign = mysql_num_rows($report_tool_assign);
?><!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 Document</title>
</head>
<body>
Select the member(s) that are required to provide information for report<br />
<strong><?php echo $_POST['report_title'];?></strong>
<form action="<?php echo $editFormAction; ?>" id="form" name="form" method="POST">
<table >
<tr>
<?php
$report_tool_assign_endRow = 0;
$report_tool_assign_columns = 4; // number of columns
$report_tool_assign_hloopRow1 = 0; // first row flag
do {
if($report_tool_assign_endRow == 0 && $report_tool_assign_hloopRow1++ != 0) echo "<tr>";
?>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><input type="hidden" name="report_title" value="<?php echo $_POST['report_title'];?>"/>
<input name="report_user_name" type="checkbox" id="report_user_name" value="<?php echo $row_report_tool_assign['realName']; ?>" />
<?php echo $row_report_tool_assign['realName']; ?>
<input name="report_user_email" type="hidden" id="report_user_email" value="<?php echo $row_report_tool_assign['emailAddress']; ?>" /></td>
</tr>
</table></td>
<?php $report_tool_assign_endRow++;
if($report_tool_assign_endRow >= $report_tool_assign_columns) {
?>
</tr>
<?php
$report_tool_assign_endRow = 0;
}
} while ($row_report_tool_assign = mysql_fetch_assoc($report_tool_assign));
if($report_tool_assign_endRow != 0) {
while ($report_tool_assign_endRow < $report_tool_assign_columns) {
echo("<td> </td>");
$report_tool_assign_endRow++;
}
echo("</tr>");
}?>
</table>
<p>
<input type="submit" name="Submit" value="Submit" />
</p>
<input type="hidden" name="MM_insert" value="form">
</form>
</body>
</html>
<?php
mysql_free_result($report_tool_assign);
?>