MySQL Forums
Forum List  »  PHP

Re: Double Insert
Posted by: James Wilson
Date: October 15, 2019 01:04PM

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

Options: ReplyQuote


Subject
Written By
Posted
October 14, 2019 12:16AM
October 15, 2019 10:11AM
October 15, 2019 10:54AM
October 15, 2019 11:06AM
October 15, 2019 12:16PM
October 15, 2019 12:30PM
October 15, 2019 12:42PM
October 15, 2019 12:53PM
Re: Double Insert
October 15, 2019 01:04PM
October 15, 2019 09:21PM
October 15, 2019 10:17PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.