我一直在尝试更新我的数据库,但它确实更新了,并且显示成功,并出现这样的 id 错误
注意:未定义变量:第 4 行 C:\wamp\www\Potifolio\update_ac.php 中的 player_id
成功:下面是我的代码,请帮助:
我的.php
<?php
include_once("connect.php");
$query = "SELECT * FROM players";
$result = mysql_query($query,$db);
?>
<table><tr>
<td>Name</td>
<td>Surname</td>
<td>Positon</td>
<td>Email</td>
<td>Passowrd</td>
<td>Email</td>
<td>Action</td>
</tr>
<?php
while($row = mysql_fetch_assoc($result)){
?>
<tr>
<td><?php echo $row['name'];?></td>
<td><?php echo $row['surname'];?></td>
<td><?php echo $row['position'];?></td>
<td><?php echo $row['password'];?></td>
<td><?php echo $row['username'];?></td>
<td><?php echo $row['name'];?></td>
<td ><a href= "update1.php?player_id=<?php echo $row['player_id'];?>">Update</a></td>
</tr>
<?php
}
?>
更新1.php
<?php
include_once("connect.php");
$player_id = $_GET['player_id'];
$query = "SELECT * FROM players where player_id ='$player_id'";
$result = mysql_query($query,$db);
$row = mysql_fetch_assoc($result);
?>
<form name = "form1"action="update_ac.php" method ="post">
<input type = "text" name="name" value="<?php echo $row['name'];?>">
<input type = "hidden" name = "player_id" ID = "player_id" value="<?php echo $row['player_id'];?>" >
<input type = "submit" name="submit" value="submit">
</form>
update_ac.php
<?php
include_once('connect.php');
$name= $_POST['name'];
$sql="UPDATE players SET name='$name' WHERE player_id = '$player_id'";
$result = mysql_query($sql);
if($result){
echo "Success";
}else {
echo "Error";
}
?>