-4

データベースを更新しようとしましたが、更新され、このような id エラーで成功が示されます

注意: 未定義の変数: C:\wamp\www\Potifolio\update_ac.php の 4 行目の player_id

成功:以下は私のコードです助けてください:

me.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
}
?>

update1.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";
}
?>
4

1 に答える 1

1

クエリをこれに変更します

$sql="UPDATE players SET name='$name' WHERE player_id = '$_POST['player_id']'";

またはこのように

$player_id = $_POST['player_id'];
$sql="UPDATE players SET name='$name' WHERE player_id = '$player_id'";

あなたの場合、 $_POST['player_id'] の実際の値を変数 $player_id に割り当てていません。

したがって、完全なコードは次のようになります

<?php 
include_once('connect.php');
if (isset($_POST['submit'])) {
    $name= $_POST['name'];
    $player_id = $_POST['player_id'];
    $sql="UPDATE players SET name='$name' WHERE player_id = '$player_id'";
    $result = mysql_query($sql);
    if($result){
        echo "Success";
    }else {
        echo "Error";
    }
}
?>
于 2013-04-28T08:41:05.897 に答える