Is the ID added after the operation?
if I have the code run unblocked it fails to add a new record:
//—-doesn’t work-I think because of the missing ID??
//$e[“on_insert”] = array(“add_rec”, null, true);
//$g->set_events($e);
function on_insert($data)// —
{
$headers = ‘Content-Type: text/html; charset=utf-8’ . “\r\n” . ‘From: [email protected]’;
$message = $data;
// Send
$message = wordwrap($message,70) . “\r\n”;
$success = mail(‘[email protected]’, ‘Nová porucha’, $message, $headers);
if (!$success) {
$errorMessage = error_get_last()[‘message’];
}
print_r($message);
}
The on_insert event does not have the newly inserted ID.
If you want to use the insert ID, you can use event on_after_insert. e.g.
$e[“on_after_insert”] = array(“add_rec”, null, true);
And yes, you need to use following, otherwise it will show Array():
$message = print_r($data,true);
Thanks Abú !!!
How to simply read the code for just this field?
I need to load more data from another table by ID…
Thank you
Sending works fine now !!! Super !!!
[ID_vytahu] => 3720
$e[“on_after_insert”] = array(“add_rec”, null, true);
$g->set_events($e);
//———————————————odeslání na email
function add_rec($data)
{
$zprava = print_r($data,true);
// Odeslat
mail(‘[email protected]’, ‘Nová porucha’, $zprava);
}
/*———————————————nyní je to takto:
$zprava=
Array
(
[ID_poruchy] => 200
[params] => Array
(
[Datum1] => 2024-03-09 14:02
[ID_vytahu] => 3720
[Nahlasil] => Zakusil
[Telefon] => 111222555
[PoruchaUdajna] => 1,2
[PU_text] => Zkoušel Pepa
)
)
*/
—————————
You can get array data as follows: e.g.
$data["params"]["Nahlasil"]