I know this question has been answered a million times but I have yet to find it put in a way that I understand. I am new to php so please bear with me. I am trying to figure out a way to update multiple records in my database at once. To try and put it simply I have a month table, day table, and day number table, and I have the results displayed with a repeat region. Updating 1 record works but not with the repeat region. I used Dreamweaver to get the code below so I have no idea how where to go from there.
php require_once('../Connections/victoria.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_update"])) && ($POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE tbl_day SET monthID=%s, dayNumber=%s, dayInput=%s WHERE dayID=%s",
GetSQLValueString($POST['monthID'], "int"),
GetSQLValueString($POST['dayNumber'], "text"),
GetSQLValueString($POST['dayInput'], "text"),
GetSQLValueString($POST['dayID'], "int"));
mysql_select_db($database_victoria, $victoria);
$Result1 = mysql_query($updateSQL, $victoria) or die(mysql_error());
}
$colname_dayRS = "-1";
if (isset($GET['monthID'])) {
$colname_dayRS = (get_magic_quotes_gpc()) ? $GET['monthID'] : addslashes($_GET['monthID']);
}
mysql_select_db($database_victoria, $victoria);
$query_dayRS = sprintf("SELECT * FROM tbl_day WHERE monthID = %s ORDER BY dayID ASC", $colname_dayRS);
$dayRS = mysql_query($query_dayRS, $victoria) or die(mysql_error());
$row_dayRS = mysql_fetch_assoc($dayRS);
$totalRows_dayRS = mysql_num_rows($dayRS);
?>
<!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>
<p> </p>
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<table width="464" align="center">
<?php do { ?>
<tr valign="baseline">
<td width="122" align="right" nowrap="nowrap">DayNumber:</td>
<td width="225"><input type="text" name="dayNumber" value="<?php echo $row_dayRS['dayNumber']; ?>" size="32" /></td>
<td align="right" nowrap="nowrap">DayInput:</td>
<td><input type="text" name="dayInput" value="<?php echo $row_dayRS['dayInput']; ?>" size="32" /></td>
</tr>
<?php } while ($row_dayRS = mysql_fetch_assoc($dayRS)); ?>
<tr valign="baseline">
<td colspan="4" align="right" nowrap="nowrap"> </td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td><input type="submit" value="Update record" /></td>
<td> </td>
<td> </td>
</tr>
</table>
<input type="hidden" name="MM_update" value="form1">
<input type="hidden" name="dayID" value="<?php echo $row_dayRS['dayID']; ?>">
</form>
<p> </p>
</body>
</html>
<?php
mysql_free_result($dayRS);
?>
If anybody could give me some assistance it would be greatly appreciated.