I wanted to get value by clicking button. But it isn’t working. Here is my code:
players.php
(header)
<?php
kick_ban(@$_POST['submit']);
getMsg();
?>
(Form)
<form method="POST" action="?go=players">
<input type="submit" name="kick" class="btn btn-warning" type="button" value="Wyrzuć" />
<input type="submit" name="ban" class="btn btn-danger" type="button" value="Zbanuj" />
<?php $idgracza = $sValue['playerid'] ?>
</form>
functions_admin.php
function kick_ban($post) {
require_once "../inc/SampRcon.class.php";
$config = getData('../inc/config.php');
$port = $config['port'];
$adrip = $config['adresip'];
$query2 = new SampRcon(''.$adrip.'', $port, "Modding1");
if ($query2->connect()) {
if(isset($_POST['kick'])){
$query2->kick($idgracza);
$_SESSION['success'] = 'Gracz o id '.$idgracza.' został pomyślnie wyrzucony z serwera.';
}
if(isset($_POST['ban'])){
$query2->ban($idgracza);
$_SESSION['success'] = 'Gracz o id '.$idgracza.' został pomyślnie zablokowany.';
}
}
else
{
$_SESSION['error'] = 'Błąd';
}
$query2->close(); // Close the connection
One problem is this line:
You are only sending the submit variable (which is actually undefined) to the function.
What you want is this:
Now I’m not saying this is a good way to code but that will send the whole post array into your function so you can access all the variables.
Another issue is when you try to access things in the kick_ban function:
and
should be:
and
The reason is that once you pass them into the kick_ban function the name of the array becomes $post instead of $_POST.
You need a hidden input to add $idgracza to the form:
Then access it in your kick_ban function:
$post['idgracza']