我在从表中删除行时遇到问题。当我单击“删除”按钮时,它确实将我带到下一页,并显示“从播放器中删除了0行”。基本上,它可以正确执行,但是我无法删除所选的行。我已经能够显示并添加到表格中。
Player.php
<table id="table table-bordered">
<tr>
<th>Id#</th>
<th>Player(s)</th>
<th>Position</th>
</tr>
if(!($stmt = $mysqli->prepare("SELECT id_Player, name_Player, position_Player FROM player s ORDER BY position_Player ASC"))){
echo "Prepare failed: " . $mysqli->connect_errno . " " . $mysqli->connect_error;
}
if(!$stmt->execute())
{
echo "Execute failed: " . $mysqli->connect_errno . " " . $mysqli->connect_error;
}
if(!$stmt->bind_result($id_Player, $name_Player, $position_Player))
{
echo "Bind failed: " . $mysqli->connect_errno . " " . $mysqli->connect_error;
}
while($stmt->fetch()){
echo "<tr><td> $id_Player </td> <td> $name_Player </td><td> $position_Player </td>";
?>
<td>
<form id="delete" method="post" action="deletePlayers.php">
<input type="submit" name="id_Player" value="Delete!"/>
</form>
</td>
</tr>
deletePlayers.php
if(!($stmt = $mysqli->prepare("DELETE FROM player WHERE id_Player = ?"))){
echo "Prepare failed: " . $stmt->errno . " " . $stmt->error;}
if(!($stmt->bind_param("s",$_POST['id_Player']))){
echo "Bind failed: " . $stmt->errno . " " . $stmt->error;}
if(!$stmt->execute()){
echo "Execute failed: " . $stmt->errno . " " . $stmt->error;}
else {
echo "Removed " . $stmt->affected_rows . " row from player. <br/><br/><strong> Returning to 'Add Players'</strong>";}
答案 0 :(得分:0)
问题出在这行代码中,
if(!($stmt->bind_param("s",$_POST['id_Player']))){}
此处$POST['id_player']
的值为Delete!
,因为您正在HTML代码中传递输入类型Submit的名称,并且我认为您没有任何等于{{1 }}。
解决方案
您需要做的是,您需要使用一个隐藏的输入,该输入将保持Delete!
的值,
id_Player