-2

我的删除页面尚未删除,但它显示成功消息。但它也显示这样的 id 错误:

注意:未定义索引:第 3 行 C:\wamp\www\Potifolio\delete.php 中的 player_id

记录删除成功:

文件:display.php

<?php
#connect to the database
include_once('connect.php');

$strSQL = "SELECT * FROM players";

// Execute the query (the recordset $rs contains the result)
$rs = mysql_query($strSQL);

// Loop the recordset $rs
// Each row will be made into an array ($row) using mysql_fetch_array

echo "
    <table border='1' >
        <tr bgcolor='#cccccc'>
            <td>Name</td>
            <td>Surname</td>
            <td>Contact Number</td>
            <td>Email</td>
            <td>Position</td>
            <td>User Nmae</td>
            <td>Password</td>
            <td colspan='2'>Action</td>
        </tr>
";

while($row = mysql_fetch_array($rs)) {
    $player_id =  $row['player_id'];
    $name =  $row['name'];
    $surname =  $row['surname'];
    $contact_number =  $row['contact_number'];
    $email =  $row['email'];
    $position =  $row['position'];
    $username =  $row['username'];
    $password =  $row['password'];
    $surname = mysql_real_escape_string($surname);
    $name = mysql_real_escape_string($name);
    $email = mysql_real_escape_string($email);
    $position = mysql_real_escape_string($position);
    $username = mysql_real_escape_string($username);
    $password = mysql_real_escape_string($password);

    echo "
        <tr bgcolor='#cccccc'>
            <td>$name</td>
            <td>$surname</td>
            <td>$contact_number</td>
            <td>$email</td>
            <td>$position</td>
            <td>$username</td>
            <td>$password</td>
            <td><a href='edit.php?player_id=$player_id'>Edit</a></td>
            <td><a href='delete.php?player_id=$player_id'>Delete</a></td>
        </tr>
    ";
}

echo'</table>';
?>

文件:删除.php

<?php 
include_once("connect.php");
$player_id = $_POST['player_id'];
$delete= "DELETE FROM players WHERE player_id = '$player_id'";
$result = mysql_query($delete);

if($result){
    echo "Record deleted successfuly ";
}else{
    echo "No data deleted";
}
?>
4

1 回答 1

1

您正在混合 PHP$_GET$_POST定义。检查这个问题GET vs. POST Best Practices,因为它包含对您问题的完整答案。

于 2013-04-28T10:32:04.280 回答