Below is a copy of the function used to build the Update Query. The result of the 'Show Create Table...' contained 1895 characters and was truncated.
CREATE TABLE `interments_data` (`per_id` int(11...
// *********************************************************************************************************** build_Update_Query
//
// This function builds a mySQL UPDATE request based on the provided parameters
//
// $tableName = Name of the table to which a record is to be updated
// $tableIndex = Name of the table index field
// $indexValue = Value of the $tableIndex Record to update
//
function build_Update_Query( $tableName, $tableIndex, $indexValue ) {
global $db;
// Determine the fields in the table
$query_STR = "SHOW FIELDS IN $tableName;";
$query_PDO = $db->query($query_STR);
$sql_Beg = "UPDATE " . $tableName . " SET ";
$sql_Mid = "";
while ( $rec_Col = $query_PDO->fetch(PDO::FETCH_ASSOC) )
{
if ( $rec_Col['Field'] != $tableIndex ) // Skip the index field
{
if ( $rec_Col['Field'] != "user_password" ) // Skip the usr_password on edit because it is disabled
{
$begParen = strpos($rec_Col['Type'], "(");
if ( $begParen != 0 )
{ $fieldType = substr($rec_Col['Type'], 0, $begParen); } // Strip length from field type ( int(11) -> int )
else
{ $fieldType = $rec_Col['Type']; }
$fieldValue = GetSQLValueString(htmlspecialchars($_POST[$rec_Col['Field']], ENT_QUOTES), $fieldType); // Clean up input values
$sql_Mid .= $rec_Col['Field'] . " = " . $fieldValue . ", "; // Set string [ fieldName = 'value', ] for each field
}
}
}
$sql_Mid = substr($sql_Mid, 0, strlen($sql_Mid)-2); // Remove last comma & space from string
$sql_End = " WHERE " . $tableIndex . " = " . $indexValue;
return $sql_Beg . $sql_Mid . $sql_End . ";";
}
Thanks!
--
James A Wilson
msgwcc@msholmes.org