do after adding with a new line

Questionsdo after adding with a new line
Jan Valenta asked 10 months ago

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);
}

5 Answers
Jan Valenta answered 10 months ago

??

$message = print_r($data, true);

Abu Ghufran Staff answered 10 months ago

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);

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Jan Valenta answered 9 months ago

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
)

)
*/

—————————

Abu Ghufran Staff answered 9 months ago

You can get array data as follows: e.g.

$data["params"]["Nahlasil"]
_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Jan Valenta answered 9 months ago

Thanks thanks thanks 😉

Your Answer

1 + 0 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?