Update DB
Update DB
Hello, I am trying to finish a small application: I would like to improve a form where there are several decimal fields, I would like to calculate a field with the values of the other fields. I tried to insert this into events before update $ data ['Celkom'] = $data ['Hmotbody'] + $data ['Srstbody']; with success. In addition I would like to update the field another table with the value of field : Celkom . Could someone help me for the sintaxe. Or is this not the right place to achieve the desired result.Thank you
Re: Update DB
Hi,
can't you do it like (code not tested) the code below?
Code to be placed in the after update function in /hooks/tabelename.php
Olaf
can't you do it like (code not tested) the code below?
Code to be placed in the after update function in /hooks/tabelename.php
Code: Select all
$sql = "UPDATE yourtablename SET yourfieldname = " . $data['Celkom'] . " WHERE yourPrimaryKeyFieldinTable = " . $selected_ID . ";";
$yourresult = sqlValue($sql);
Some postings I was involved, you might find useful:
Multi Path Upload (MPU) / dynamic upload folder; SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button
Multi Path Upload (MPU) / dynamic upload folder; SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button
Re: Update DB
Hello onoehring and thank you very much for your help, I didn't manage to get your code to work but you helped me with the syntax. I finally found a less elegant form than yours which works for the moment. I also reconfigured my database so that the IDs match. You know, I am not a programmer I do a few small programs from time to time for our breeders association and in the meantime I forget the exact syntax a little. Thank you again.
function olkralikov_after_update ($ data, $ memberInfo, & $ args) {
$ id = makeSafe ($ data [id]);
$ sqlx = sqlValue ("Select Celkom from Olkralikov WHERE Olkralikov.id = $ id");
sql ("UPDATE Zviera SET Ocenenie = '$ sqlx' WHERE Zviera.id = $ id");
return TRUE;
function olkralikov_after_update ($ data, $ memberInfo, & $ args) {
$ id = makeSafe ($ data [id]);
$ sqlx = sqlValue ("Select Celkom from Olkralikov WHERE Olkralikov.id = $ id");
sql ("UPDATE Zviera SET Ocenenie = '$ sqlx' WHERE Zviera.id = $ id");
return TRUE;