Copy link to clipboard
Copied
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);
?>
Copy link to clipboard
Copied
I haven't figured out the whole issue yet, but I can tell you what line is causing the error:
for ($j = 0, $len = count($_POST['calDate']); $j < $len; $j++) {
If "calDate" is empty at this point and you didn't make sure $_POST['calDate'] isset then you get the error that you have an undefined index. Can you highlight what you changed from the code that was working and only updating one record compared to this?
Copy link to clipboard
Copied
Sure. Thanks for looking.
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());
}
}
The areas in bold are the only things changed from the working code.
Copy link to clipboard
Copied
Hi all. I'm still looking for help on this. Anyone got an idea?
Copy link to clipboard
Copied
I think you have your answer, no?
the calDate value must be null at that point. You can easily check that by inserting some breakpoints in your code for debugging....
Copy link to clipboard
Copied
I don't have the answer actually. I'm not versed enough in PHP to figure this out. I can make it update with one record, but nothing I've tried, no matter how many forum entries I read, seems to work when updating multiple records at once. I give up.