/* example : table = point coloum = total, user. */ /* this is just example */ /* count on giver total point */ $pointgiver = $db->query("SELECT `total` FROM `point` WHERE `user` = ''.$systemUser->id.''")->fetchColumn(); /* count on receiver total point */ $pointreceive = $db->query("SELECT `total` FROM `point` WHERE `user` = ''.$user['id'].''")->fetchColumn(); /* executor */ if (isset($_POST['submit'])) { $error = []; $point = isset($_POST['point']) ? trim($_POST['point']) : false; if (empty($_POST['text'])) { $error['point'][] = _t('You cant send empty point!','system'); } if ($point >= $pointgiver) { $error['point'][] = _t('You cant send more than your point!','system'); } if ($user['id'] == $systemUser->id) { $error['point'][] = _t('You cant send to your self!','system'); } $flood = $tools->antiflood(); if ($flood) { $error['flood'][] = sprintf(_t('You cannot add point so often. Please, wait %d seconds.','system'), $flood); } /* update data for receiver */ if (!$error) { $receive = $pointreceive + $point; $db->prepare(' UPDATE `point` SET `total` = ? WHERE `user` = ? ')->execute([ $receive, $user['id'], ]); } /* update data for giver */ if (!$error) { $given = $pointgiver - $point; $db->prepare(' UPDATE `point` SET `total` = ? WHERE `user` = ? ')->execute([ $given, $user['id'], ]); } $db->query("OPTIMIZE TABLE `point`"); } /* form (edit form action) */ echo '
'. (isset($error['flood']) ? '

'.implode($error['flood']).'

' : ''). (isset($error['point']) ? '

'.implode($error['point']).'

' : ''); echo '

Point giver

'; echo '

'; echo '
';