hello pmmp community , I use this code to connect mysql database in my plugin PHP: <?phpnamespace ReportSpace;use pocketmine\command\Command;use pocketmine\command\CommandSender;use pocketmine\plugin\PluginBase;use pocketmine\plugin\Plugin as Plugin;use pocketmine\plugin\PluginDescription;use pocketmine\plugin\PluginLoader;use pocketmine\Server;use pocketmine\utils\TextFormat as T;use pocketmine\player;class Main extends PluginBase{ public $HOST; public $USER; public $PASS; public $DB; public $CON; public function CON() { $this->HOST = "localhost"; $this->USER = "root"; $this->PASS = ""; $this->DB = "minespace"; $con = new \mysqli($this->HOST, $this->USER, $this->PASS); if ($con->connect_error) { $this->getServer()->shutdown(); } $con->query("CREATE DATABASE IF NOT EXISTS $this->DB CHARACTER SET utf8 COLLATE utf8_general_ci"); $this->CON = new \mysqli($this->HOST, $this->USER, $this->PASS, $this->DB); if ($this->CON->connect_error) { $this->getServer()->shutdown(); } $this->CON->query("CREATE TABLE IF NOT EXISTS report ( player varchar(255) , hacker varchar(255) , problem varchar(255) )"); $this->CON->query("CREATE TABLE IF NOT EXISTS sugg ( player varchar(255) , sugg varchar(255) )"); $this->CON->query("CREATE TABLE IF NOT EXISTS inst ( player varchar(255) , url varchar(255), PRIMARY KEY (url) )"); $this->CON->query("CREATE TABLE IF NOT EXISTS yout ( player varchar(255) , url varchar(255), PRIMARY KEY (url) )"); return $this->CON; } public function onEnable() { $this->getLogger()->info(T::DARK_GREEN . "ReportSpace Created by s_ki OR ski12"); } public function onCommand(CommandSender $sender, Command $cmd, string $label, array $args): bool { switch ($cmd->getName()) { case 'contact': $api = $this->getServer()->getPluginManager()->getPlugin("FormAPI"); if ($api === null || $api->isDisabled()){return false;} $form = $api->createSimpleForm(function (Player $player, int $data = null){ $result = $data; if ($result === null){return false;} switch ($result) { case 0: $this->report($player); break; case 1: $this->sugg($player); break; case 2: $this->inst($player); break; case 3: $this->yout($player); } }); $form->setTitle(T::GOLD . "MineSpace"); $form->addButton(T::DARK_PURPLE . "Report a Hacker", 0); $form->addButton(T::DARK_PURPLE . "Complaints and Suggestions", 0); $form->addButton(T::DARK_PURPLE . "Instagrammer Rank Request", 0); $form->addButton(T::DARK_PURPLE . "Youtuber Rank Request", 0); $form->sendToPlayer($sender); return true; } } public function report(Player $player) { $api = $this->getServer()->getPluginManager()->getPlugin("FormAPI"); if ($api === null || $api->isDisabled()){return false;} $n = $player->getName(); $form = $api->createCustomForm(function (Player $player, array $data){ $result = $data[0]; if ($result != null){return false;} $n = $player->getName(); switch ($result) { case 0: $this->CON()->query("INSERT INTO `report`(`PLAYER`, `HACKER`, `PROBLEM`) VALUES ($n, $data[1], $data[2])"); $player->sendMessage(T::GREEN . "your Report was successfully sent"); break; } }); $form->setTitle(T::GOLD . "MineSpace"); $form->addLabel(T::GREEN . "Report a Hacker"); $form->addInput("Hacker Name", "eg : $n", ""); $form->addInput("problem", "eg : fly in the game", ""); $form->sendToPlayer($player); return true; } public function sugg(Player $player) { $api = $this->getServer()->getPluginManager()->getPlugin("FormAPI"); if ($api === null || $api->isDisabled()){return false;} $n = $player->getName(); $form = $api->createCustomForm(function (Player $player, array $data){ $result = $data[0]; if ($result != null){return false;} $n = $player->getName(); switch ($result) { case 0: $this->CON()->query("INSERT INTO `sugg`(`PLAYER`, `sugg`) VALUES ($n, $data[1])"); $player->sendMessage(T::GREEN . "your Complaints or Suggestions was successfully sent"); break; } }); $form->setTitle(T::GOLD . "MineSpace"); $form->addLabel(T::GREEN . "Complaints and Suggestions"); $form->addInput("message", "eg : x o game disabled", ""); $form->sendToPlayer($player); return true; } public function inst(Player $player) { $api = $this->getServer()->getPluginManager()->getPlugin("FormAPI"); if ($api === null || $api->isDisabled()){return false;} $n = $player->getName(); $form = $api->createCustomForm(function (Player $player, array $data){ $result = $data[0]; if ($result != null){return false;} $n = $player->getName(); switch ($result) { case 0: $this->CON()->query("INSERT INTO `inst`(`PLAYER`, `url`) VALUES ($n, $data[1])"); $player->sendMessage(T::GREEN . "your Request was successfully sent"); break; } }); $form->setTitle(T::GOLD . "MineSpace"); $form->addLabel(T::GREEN . "Instagrammer Rank Request"); $form->addLabel(T::GREEN . "شروط الانستقرامر هنا يا كفكف"); $form->addInput("your instagram post URL", "eg : https://www.instagram.com/p/BgD7WcPhgoE/", ""); $form->sendToPlayer($player); return true; } public function yout(Player $player) { $api = $this->getServer()->getPluginManager()->getPlugin("FormAPI"); if ($api === null || $api->isDisabled()){return false;} $n = $player->getName(); $form = $api->createCustomForm(function (Player $player, array $data){ $result = $data[0]; if ($result != null){return false;} $n = $player->getName(); switch ($result) { case 0: $this->CON()->query("INSERT INTO `yout`(`PLAYER`, `url`) VALUES ($n, $data[1])"); $player->sendMessage(T::GREEN . "your Request was successfully sent"); break; } }); $form->setTitle(T::GOLD . "MineSpace"); $form->addLabel(T::GREEN . "Youtuber Rank Request"); $form->addLabel(T::GREEN . "شروط اليوتيوبر هنا يا كفكف"); $form->addInput("your youtube video URL", "eg : https://youtu.be/L_FmO3WtG6Q", ""); $form->sendToPlayer($player); return true; }} but if I do /contact and fill the form nothing inserts to database although I used the same code in another plugin and it works
Uhm, I see what it is. You should probably read about callables. The problem is that you can't call `$this` inside a callable, very similar to this issue. Assuming you're new to PHP callables, I'd advise you create a separate class function for the form instead. Like so: PHP: public function onFormSubmit(Player $player, int $data = null){ $result = $data; if ($result === null){return false;} switch ($result) { case 0: $this->report($player); break; case 1: $this->sugg($player); break; case 2: $this->inst($player); break; case 3: $this->yout($player); break; }} Now you will want that function to be called when the player submits the form. So you convert the class function into a callable by putting it in an array in such a way: PHP: $callable = [$yourClassInstance, "yourClassFunction"]; Like so: PHP: $form = $api->createCustomForm([$this, "onFormSubmit"]);