Update multiple records in php
I've seen this question asked in the forum and I've tried to use the answers provided but I'm not having any luck after 24 hrs. So maybe someone can help.
I have a calendar and I'd like to update multiple records at once. So far I have a page with a form that sends two form values - "startDate" and "endDate" to a second page. The second page then displays a repeat region with the result set (records between startDate and endDate). If I do simple update record only the last record in the resultset updates. When I add (what I believe based on what I've read here) is the code to update multiple records I get an error:
Notice: Undefined index: calDate in C:\wamp\www\GrammyRoses\admingr2.php on line 38
I can't figure out what I'm doing wrong. Here is the code for the second page:
<?php require_once('Connections/connGR.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']);
}
for ($j = 0, $len = count($_POST['calDate']); $j < $len; $j++) {
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "dateedit")) {
$updateSQL = sprintf("UPDATE calendar SET Viviana=%s, Leah=%s, Kaylea=%s, Chelsea=%s WHERE calDate=%s",
GetSQLValueString($_POST['Viviana'][$j], "text"),
GetSQLValueString($_POST['Leah'][$j], "text"),
GetSQLValueString($_POST['Kaylea'][$j], "text"),
GetSQLValueString($_POST['Chelsea'][$j], "text"),
GetSQLValueString($_POST['calDate'][$j], "date"));
mysql_select_db($database_connGR, $connGR);
$Result1 = mysql_query($updateSQL, $connGR) or die(mysql_error());
}
}
$colname_rsAV = "-1";
if (isset($_POST['startDate'])) {
$colname_rsAV = $_POST['startDate'];
}
$colname2_rsAV = "-1";
if (isset($_POST['endDate'])) {
$colname2_rsAV = $_POST['endDate'];
}
mysql_select_db($database_connGR, $connGR);
$query_rsAV = sprintf("SELECT * FROM calendar WHERE calDate >= %s AND calDate < %s", GetSQLValueString($colname_rsAV, "date"),GetSQLValueString($colname2_rsAV, "date"));
$rsAV = mysql_query($query_rsAV, $connGR) or die(mysql_error());
$row_rsAV = mysql_fetch_assoc($rsAV);
$totalRows_rsAV = mysql_num_rows($rsAV);
?>
<!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" />
</head>
<body>
<div id="mainContainer2">
<?php require_once('includes/nav.php'); ?>
<img src="images/title_availability.png" width="720" height="70" />
<form name="dateedit" action="<?php echo $editFormAction; ?>" method="POST" id="dateedit">
<div id="resultContainer">
<table width="720" border="0">
<tr>
<td width="120" align="center">Date</td>
<td width="120" align="center">Vivianna</td>
<td width="120" align="center">Leah</td>
<td width="120" align="center">Kaylea</td>
<td width="120" align="center">Chelsea</td>
</tr>
</table>
<?php do { ?>
<table width="720" border="0">
<tr>
<td width="120" align="center"><label for="calDate"></label>
<input name="calDate" type="text" class="formField" id="calDate" value="<?php echo $row_rsAV['calDate']; ?>" size="16" maxlength="12" /></td>
<td width="120" align="center"><input name="Viviana" type="text" class="formField" id="Viviana" value="<?php echo $row_rsAV['Viviana']; ?>" size="8" maxlength="8" /></td>
<td width="120" align="center"><input name="Leah" type="text" class="formField" id="Leah" value="<?php echo $row_rsAV['Leah']; ?>" size="8" maxlength="8" /></td>
<td width="120" align="center"><input name="Kaylea" type="text" class="formField" id="Kaylea" value="<?php echo $row_rsAV['Kaylea']; ?>" size="8" maxlength="8" /></td>
<td width="120" align="center"><input name="Chelsea" type="text" class="formField" id="Chelsea" value="<?php echo $row_rsAV['Chelsea']; ?>" size="8" maxlength="8" /></td>
</tr>
</table>
<?php } while ($row_rsAV = mysql_fetch_assoc($rsAV)); ?>
</div>
<input name="submit" type="submit" value="Submit" />
<input type="hidden" name="MM_update" value="dateedit" />
</form>
<!--EndMainContainer--></div>
</body>
</html>
<?php
mysql_free_result($rsAV);
?>
