<body>
<?php include('form.php') ?>
<form action="index.php" method="post">
<select name="id"><?php playerID($tournament); ?></select>
<input type="text" name="name" value="<?php playerName($tournament); ?>">
<input type="submit" value="Save Player">
</form>
</body>
function playerName($tournament) {
$player = getPlayer($tournament);
echo isset($player) ? $player->Name : '';
}
此代码适用于我,但是当我按下“保存播放器”时提交我无法将$锦标赛发送到呼叫功能&#39; updatePlayer($ tournament)&#39;
updatePlayer($tournament);
function updatePlayer($tournament) {
if (isset($_POST['id'])) {
$id = $_POST['id'];
$player = $tournament->getPlayer($id);
$player->Name = $_POST['name'];
$player->Phone = $_POST['phone'];
$player->Active = $_POST['active'];
}
}
我需要这样的事情:
<input type="submit" value="Save Player" <?php [SEND $tournament FROM HERE?] ?>>
答案 0 :(得分:0)
index.php上的表单需要实例化您定义的函数。为此,可以在页面顶部进行简单的$ _POST检测。从那里,您可以按预期验证并运行该功能。
if(isset($_POST['name')){
//validation here???
updatePlayer($_POST['name']);
}