Questions and discussion about using ProcessMaker: user interface, running cases & functionality
#815819
Hello, I have a trigger that gives me an error that I don't understand:
Code: Select all
try {
	
$processId = @@PROCESS;
$caseId = @@TASK; 
$applicationId = @@APPLICATION;
$userLogged = @@USER_LOGGED;
$estudanteNome = @@nomeEstudante;
$estudanteNumero = @@nEstudante;
$cursoTeSP = @@cursoEstudante;
$supervisorEmpresa = @@supervisorEstagio;
$instituicaoDesignacao = @@entidadeEstagio;
$anoLetivo = @@anoLetivo;
$done = false;
$var = null; 
	
$query = "select PROCESSID FROM PMT_PROCESSO_ESTAGIO WHERE ProcessID = '$processId'"; 
$result = executeQuery($query);
	
	if (is_array($result) and count($result) > 0) {
   //Inserir código para fazer update
		

		
      $result = executeQuery("UPDATE PMT_PROCESSO_ESTAGIO 
          SET ESTUDANTENOME='$nomeEstudante', ESTUDANTENUMERO = '$numeroEstudante', 
          CURSOTESP = '$cursoTeSP', INSTITUICAODESIGNACAO = '$instituicaoDesignacao', 
          SUPERVISOREMPRESA = '$supervisorEmpresa', ANOLETIVO = '$anoLetivo' 
          WHERE PROCESSID = '$processId'");
		
if ($result == 0) {
    $g = new G();
    $g->SendMessageText("Did not update any record in PM Table.", "ERROR");
}	
	} else {
		// Inserir código para fazer INSERT na PM Table 	
		$query = "INSERT INTO PMT_PROCESSO_ESTAGIO (
				PROCESSID, 
				CASEID, 
				APPLICATIONID, 
				USERLOGGED, 
				ESTUDANTENOME, 
				ESTUDANTENUMERO, 
				ESTUDANTENUMEROTELEMOVEL, 
				CURSOTESP, 
				INSTITUICAODESIGNACAO, 
				INSTITUICAOTELEMOVEL, 
				INSTITUICAOMORADA, 
				INSTITUICAOCODIGOPOSTAL, 
				INSTITUICAOEMAILPESSOADECONTACTO, 
				ORIENTADORESCOLA, 
				SUPERVISOREMPRESA, 
				ANOLETIVO, 
				DATAINICIO, 
				DONE) VALUES (
				'$processId', 
				'$caseId', 
				'$applicationId',
				'$userLogged',
				'$estudanteNome',
				'$estudanteNumero',
				'$var',
				'$cursoTeSP',
				'$instituicaoDesignacao',
				'$var',
				'$var',
				'$var',
				'$var',
				'$var', 
				'$supervisorEmpresa',
				'$anoLetivo',
				'$var',
				$done)";
		
		$result = executeQuery($query); 
		
	}

	$f = new G(); 
	$f->SendMessageText("ALL LINES SAVED IN PM TABLE", "INFO"); 
}
//catch any exceptions:
catch(Exception $e) {
	
  $g = new G();
  $g->SendMessageText($e->getMessage(), 'ERROR: Could not save data to Database');
}
the error is on the picture Image


Any Clue ??
#815823
I see two errors.
Change this part:
Code: Select all
   if ($result == 0) {
       $g = new G();
       $g->SendMessageText("Did not update any record in PM Table.", "ERROR");
   }  
   } else {
TO:
Code: Select all
   if ($result == 0) {
       $g = new G();
       $g->SendMessageText("Did not update any record in PM Table.", "ERROR");
   } else {
Second, change this:
Code: Select all
$g->SendMessageText($e->getMessage(), 'ERROR: Could not save data to Database');
To:
Code: Select all
$g->SendMessageText('ERROR: Could not save data to Database: '.$e->getMessage(), 'ERROR');
If you want to see the error messages from MySQL, then you need to edit your /workflow/engine/config/env.ini file and add this line:
Code: Select all
debug = 1
By the way, if you don't catch the Exceptions in your trigger code, they will be displayed in the @@__ERROR__ variable in Debug Mode.

If you are using MySQL in a Linux server, then table and field names are case sensitive, so you will need to change this:
Code: Select all
 $query = "select PROCESSID FROM PMT_PROCESSO_ESTAGIO WHERE ProcessID = '$processId'";  
To:
Code: Select all
 $query = "select PROCESSID FROM PMT_PROCESSO_ESTAGIO WHERE PROCESSID = '$processId'";  
To debug your SQL queries, create case variables for your queries like this:
Code: Select all
@@query = "select PROCESSID FROM PMT_PROCESSO_ESTAGIO WHERE PROCESSID = '$processId'";  
$result = executeQuery(@@query);
Then copy the SQL query from the @@query variable in the debugger and try it manually inside MySQL (through the command line or in PhpMyAdmin). For example:
Code: Select all
mysql -u root -p
use wf_workflow;
select PROCESSID FROM PMT_PROCESSO_ESTAGIO WHERE PROCESSID = 'XXXXXXX';
Also, if any of your fields are numbers in the SQL query, then they shouldn't be enclosed in single quotation marks.

Also you should prevent SQL injection attacks like this:
Code: Select all
$var1 = mysql_real_escape_string(@@var1);
$query = "SELECT * FROM TABLEX WHERE FIELDA='$var1'";

Hello. For rental housing, there are software solu[…]

Experience heightened pleasure with Cenforce 100 M[…]

Get an instant solution to move emails to MBOX for[…]

Most Demanding OST to PST Converter

The most demanding OST to PST Converter is TrijaT[…]