prepare($sql); $stmt->execute([$post_content['sn']]); $messages = $stmt->fetch(); $messages = $messages[0]; $post_content['equipmentid'] = $messages; } $post_content['created'] = $date; $post_content['createdby'] = $username; } else { //do nothing } //CREAT NEW ARRAY AND MAP TO CLAUSE if(isset($post_content) && $post_content!=''){ foreach ($post_content as $key => $var){ if ($key == 'submit' || $key == 'rowID' || $key == 'sn'){ //do nothing } else { $criterias[$key] = $var; $clause .= ' , '.$key.' = ?'; $clause_insert .= ' , '.$key.''; $input_insert .= ', ?'; // ? for each insert item $execute_input[]= $var; // Build array for input } } } //CLEAN UP INPUT $clause = substr($clause, 2); //Clean clause - remove first comma $clause_insert = substr($clause_insert, 2); //Clean clause - remove first comma $input_insert = substr($input_insert, 1); //Clean clause - remove first comma //QUERY AND VERIFY ALLOWED if ($command == 'update' && !isset($post_content['delete']) && isAllowed('history',$profile,$permission,'U') === 1){ $sql = 'UPDATE equipment_history SET '.$clause.' WHERE rowID = ?'; $execute_input[] = $id; $stmt = $pdo->prepare($sql); $stmt->execute($execute_input); } elseif ($command == 'insert' && !isset($post_content['delete']) && isAllowed('history',$profile,$permission,'C') === 1){ $sql = 'INSERT INTO equipment_history ('.$clause_insert.') VALUES ('.$input_insert.')'; $stmt = $pdo->prepare($sql); $stmt->execute($execute_input); } elseif ($command == 'delete' && isAllowed('history',$profile,$permission,'D') === 1){ $stmt = $pdo->prepare('DELETE FROM equipment_history WHERE rowID = ?'); $stmt->execute([ $id ]); //Add deletion to changelog changelog($dbname,'history',$id,'Delete','Delete',$username); } else { //do nothing } ?>