|
12 | 12 | exit(); |
13 | 13 | } |
14 | 14 |
|
15 | | -include "global.php"; |
16 | | -$link = mysqli_connect($hostName, $userName, $password, $databaseName) or die ("Error connect to database"); |
17 | | -mysqli_set_charset($link, "utf8"); |
| 15 | +include "global.php"; |
| 16 | +$link = mysqli_connect($hostName, $userName, $password, $databaseName); |
| 17 | +if (!$link) { |
| 18 | + error_log('DB connection error: ' . mysqli_connect_error()); |
| 19 | + exit(); |
| 20 | +} |
| 21 | +mysqli_set_charset($link, 'utf8'); |
18 | 22 |
|
19 | 23 | include 'botdata.php'; // keys etc. |
20 | 24 | include 'func_gen.php'; |
|
26 | 30 |
|
27 | 31 | ################################# |
28 | 32 |
|
29 | | -if (isset($data['message']['chat']['id'])) |
30 | | -{ |
31 | | - $chat_id = $data['message']['chat']['id']; |
32 | | -} |
33 | | -elseif(isset($data['callback_query']['message']['chat']['id'])) |
34 | | -{ |
35 | | - $chat_id = $data['callback_query']['message']['chat']['id']; |
36 | | -} |
37 | | -elseif(isset($data['inline_query']['from']['id'])) |
38 | | -{ |
39 | | - $chat_id = $data['inline_query']['from']['id']; |
40 | | -} |
| 33 | +if (isset($data['message']['chat']['id'])) { |
| 34 | + $chat_id = intval($data['message']['chat']['id']); |
| 35 | +} elseif (isset($data['callback_query']['message']['chat']['id'])) { |
| 36 | + $chat_id = intval($data['callback_query']['message']['chat']['id']); |
| 37 | +} elseif (isset($data['inline_query']['from']['id'])) { |
| 38 | + $chat_id = intval($data['inline_query']['from']['id']); |
| 39 | +} |
41 | 40 |
|
42 | 41 | // Register new user in DB |
43 | 42 | if(isset($data['callback_query']['message']['chat']['username']) && $data['callback_query']['message']['chat']['username'] != ''){ |
44 | | - $fname = $data['callback_query']['message']['chat']['first_name']; |
45 | | - $lname = $data['callback_query']['message']['chat']['last_name']; |
46 | | - $uname = $data['callback_query']['message']['chat']['username']; |
47 | | -} else{ |
48 | | - $fname = $data['message']['from']['first_name']; |
49 | | - $lname = $data['message']['from']['last_name']; |
50 | | - $uname = $data['message']['from']['username']; |
51 | | -} |
52 | | -$time = time(); |
53 | | - |
54 | | - if(empty($uname))$uname = 'undefined'; |
55 | | - |
56 | | - $str2select = "SELECT * FROM `users` WHERE `chatid`='$chat_id'"; |
57 | | - $result = mysqli_query($link, $str2select); |
58 | | - if(mysqli_num_rows($result) == 0){ |
59 | | - $str2ins = "INSERT INTO `users` (`chatid`,`username`,`tgr_ton`,`tgr_bep20`,`ton_ton`,`tgr_ton_full`,`ton_ton_full`,`ref`,`phone`) VALUES ('$chat_id','$uname', '0', '0', '0', '0', '0', '0', '0')"; |
60 | | - mysqli_query($link, $str2ins); |
61 | | - $result = mysqli_query($link, $str2select); |
62 | | - } |
63 | | - $row = @mysqli_fetch_object($result); |
| 43 | + $fname = $data['callback_query']['message']['chat']['first_name']; |
| 44 | + $lname = $data['callback_query']['message']['chat']['last_name']; |
| 45 | + $uname = $data['callback_query']['message']['chat']['username']; |
| 46 | +} else{ |
| 47 | + $fname = $data['message']['from']['first_name']; |
| 48 | + $lname = $data['message']['from']['last_name']; |
| 49 | + $uname = $data['message']['from']['username']; |
| 50 | +} |
| 51 | +$time = time(); |
| 52 | + |
| 53 | + if (empty($uname)) { |
| 54 | + $uname = 'undefined'; |
| 55 | + } |
| 56 | + $uname = trim(filter_var($uname, FILTER_SANITIZE_FULL_SPECIAL_CHARS)); |
| 57 | + |
| 58 | + $stmt = $link->prepare("SELECT * FROM `users` WHERE `chatid` = ?"); |
| 59 | + if ($stmt === false) { |
| 60 | + error_log('Prepare failed: ' . $link->error); |
| 61 | + exit(); |
| 62 | + } |
| 63 | + $stmt->bind_param('i', $chat_id); |
| 64 | + if (!$stmt->execute()) { |
| 65 | + error_log('SQL Error: ' . $stmt->error); |
| 66 | + } |
| 67 | + $result = $stmt->get_result(); |
| 68 | + if (mysqli_num_rows($result) == 0) { |
| 69 | + $stmtIns = $link->prepare("INSERT INTO `users` (`chatid`,`username`,`tgr_ton`,`tgr_bep20`,`ton_ton`,`tgr_ton_full`,`ton_ton_full`,`ref`,`phone`) VALUES (?, ?, 0, 0, 0, 0, 0, 0, 0)"); |
| 70 | + if ($stmtIns === false) { |
| 71 | + error_log('Prepare failed: ' . $link->error); |
| 72 | + exit(); |
| 73 | + } |
| 74 | + $stmtIns->bind_param('is', $chat_id, $uname); |
| 75 | + if (!$stmtIns->execute()) { |
| 76 | + error_log('SQL Error: ' . $stmtIns->error); |
| 77 | + } |
| 78 | + $stmtIns->close(); |
| 79 | + |
| 80 | + $stmt->execute(); |
| 81 | + $result = $stmt->get_result(); |
| 82 | + } |
| 83 | + $row = @mysqli_fetch_object($result); |
| 84 | + $stmt->close(); |
64 | 85 |
|
65 | 86 | // Register new user in DB |
66 | 87 |
|
|
511 | 532 | } |
512 | 533 | }else{ |
513 | 534 |
|
514 | | - $str5select = "SELECT `action` FROM `temp_sess` WHERE `chatid`='$chat_id' ORDER BY `rowid` DESC LIMIT 1"; |
515 | | - $result5 = mysqli_query($link, $str5select); |
516 | | - $row5 = @mysqli_fetch_object($result5); |
| 535 | + $stmt5 = $link->prepare("SELECT `action` FROM `temp_sess` WHERE `chatid` = ? ORDER BY `rowid` DESC LIMIT 1"); |
| 536 | + if ($stmt5 === false) { |
| 537 | + error_log('Prepare failed: ' . $link->error); |
| 538 | + } else { |
| 539 | + $stmt5->bind_param('i', $chat_id); |
| 540 | + if (!$stmt5->execute()) { |
| 541 | + error_log('SQL Error: ' . $stmt5->error); |
| 542 | + } |
| 543 | + $result5 = $stmt5->get_result(); |
| 544 | + $row5 = @mysqli_fetch_object($result5); |
| 545 | + $stmt5->close(); |
| 546 | + } |
517 | 547 | // Wallet |
518 | 548 | if(preg_match("/withdrawWallet\|/", $row5->action)){ |
519 | 549 | withdrawFundsWait4Sum($data, $row5); |
|
0 commit comments