如何在删除页面时修复删除页面

时间:2013-04-28 10:23:36

标签: php mysql

我的删除页面尚未删除但显示成功消息。但它也会显示如下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>';
?>

文件:delete.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";
}
?>

1 个答案:

答案 0 :(得分:1)

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