HTTP error 500 after inserting a record with customization in hook file (after insert)

Got something cool to share with AppGini users? Feel free to post it here!
Post Reply
fgazza
Veteran Member
Posts: 206
Joined: 2019-04-30 17:37

HTTP error 500 after inserting a record with customization in hook file (after insert)

Post by fgazza » 2025-08-25 16:16

in my appgini hooks folder I have a correspondenza_protocol.php file that contains the following code:

Code: Select all


<?php
	// For help on using hooks, please refer to https://bigprof.com/appgini/help/working-with-generated-web-database-application/hooks

	function protocollo_corrispondenza_init(&$options, $memberInfo, &$args){

		return TRUE;
	}

	function protocollo_corrispondenza_header($contentType, $memberInfo, &$args){
		$header='';

		switch($contentType){
			case 'tableview':
				$header='';
				break;

			case 'detailview':
				$header='';
				break;

			case 'tableview+detailview':
				$header='';
				break;

			case 'print-tableview':
				$header='';
				break;

			case 'print-detailview':
				$header='';
				break;

			case 'filters':
				$header='';
				break;
		}

		return $header;
	}

	function protocollo_corrispondenza_footer($contentType, $memberInfo, &$args){
		$footer='';

		switch($contentType){
			case 'tableview':
				$footer='';
				break;

			case 'detailview':
				$footer='';
				break;

			case 'tableview+detailview':
				$footer='';
				break;

			case 'print-tableview':
				$footer='';
				break;

			case 'print-detailview':
				$footer='';
				break;

			case 'filters':
				$footer='';
				break;
		}

		return $footer;
	}

	function protocollo_corrispondenza_before_insert(&$data, $memberInfo, &$args){

		return TRUE;
	}
	

	function protocollo_corrispondenza_after_insert($data, $memberInfo, &$args){

		$sql_string = "SELECT MAX(n_protocollo) + 1 FROM protocollo_corrispondenza;";
		$new_n_protocollo = sqlValue($sql_string, $o);
		$sql_string = "UPDATE protocollo_corrispondenza set n_protocollo = " . $new_n_protocollo . " WHERE prikey = " . $data['selectedID'] . ";";
		$result = sql($sql_string, $o);

		mysqli_free_result($result);

		return TRUE;
	}

	function protocollo_corrispondenza_before_update(&$data, $memberInfo, &$args){

		return TRUE;
	}

	function protocollo_corrispondenza_after_update($data, $memberInfo, &$args){

		return TRUE;
	}

	function protocollo_corrispondenza_before_delete($selectedID, &$skipChecks, $memberInfo, &$args){

		return TRUE;
	}

	function protocollo_corrispondenza_after_delete($selectedID, $memberInfo, &$args){

	}

	function protocollo_corrispondenza_dv($selectedID, $memberInfo, &$html, &$args){
		
		if(!in_array($memberInfo['group'], ['Admins'])) {
			ob_start();
			?>
			<script>
				$j(function() {
					$j('#n_protocollo').prop('readonly', true);
				})
			</script>
			<?php
			$html .= ob_get_clean();
		}

	}

	function protocollo_corrispondenza_csv($query, $memberInfo, &$args){

		return $query;
	}
	function protocollo_corrispondenza_batch_actions(&$args){

		return array();
	}


The code allows me to automatically add a number to the n_protocollo field, incrementing it by 1 compared to the number contained in the same field of the previous record. Only those belonging to the "Admins" group can manually modify the n_protocollo field. Everything works fine except that once the new record is added, I am redirected to the page https://mywebsite/portale/protocollo_co ... a_view.php and the page displays the error: "The page is not working. mywebsite .it is currently unable to handle the request. HTTP ERROR 500"

The record is inserted correctly and n_protocollo works (i.e., a number one larger than the previous record is inserted correctly). The problem is the table view page that is subsequently loaded: the page throws an error. If I reload the page, it still doesn't work. If I copy the page address and paste it into a new tab, then it works and I see the "table view" of registro_protocollo correctly.

Could someone help me figure out what the problem is?

Thank you so much!

saymaad
AppGini Super Hero
AppGini Super Hero
Posts: 55
Joined: 2024-06-03 16:17

Re: HTTP error 500 after inserting a record with customization in hook file (after insert)

Post by saymaad » 2025-08-25 16:54

sqlValue accepts one parameter only, that's the first culprit I see, try changing :
$new_n_protocollo = sqlValue($sql_string, $o);

To

Code: Select all

 $new_n_protocollo = sqlValue($sql_string); 
Also try without using mysqli_free_result($result);

Post Reply