-2

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";
}
?>
halfer
  • 19,471
  • 17
  • 87
  • 173
Humphrey
  • 2,473
  • 3
  • 27
  • 38

1 Answers1

1

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.

Community
  • 1
  • 1
Rolando Isidoro
  • 4,715
  • 2
  • 31
  • 42
  • Thanks I got it though from Phill but now how can I make it be with a Yes or no option ? so that users do not make mistaskes – Humphrey Apr 28 '13 at 10:34
  • 1
    You'll have to use Javascript to create a delete confirmation dialog. Google for it or search here on stackoverflow, I'm sure you'll find plenty of examples. – Rolando Isidoro Apr 28 '13 at 10:37
  • okay but one day I did it with plain php it could not popup bu ti could take me to two links yes or no – Humphrey Apr 28 '13 at 15:32