douji5329 2013-04-28 10:23
浏览 29

如何在删除页面时修复删除页面[关闭]

My delete page does not delete yet it shows a success message. But it also displays an id error like this:

Notice: Undefined index: player_id in C:\wamp\www\Potifolio\delete.php on line 3

Record deleted successfully:

File: 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>';
?>

File: 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条回答 默认 最新

  • dream5694 2013-04-28 10:32
    关注

    You're mixing PHP $_GET and $_POST definitions. Check this question GET vs. POST Best Practices, as it contains the a complete answer to your problem.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题