0

My goal is to display the entire table e.g SELECT * FROM athlete and include button for each row in the table output, that when pressed will remove that row from the database.

I have followed another post and shown below is what I have so far but does not work:

//if(isset($_POST['delete_id']) && (!empty($_POST['delete_id']))) 
if(isset($_POST['Delete'])){ 

$delete_id = mysql_real_escape_string($_POST['delete_id']); 
echo("deletebutton" . $delete_id);
//mysql_query("DELETE FROM KeepScores WHERE `id`=".$delete_id); 
//header('Location: main.php'); 
} 

else
{
$query = 'SELECT * FROM athlete';
$result = mysql_query($query);


$self = $_SERVER['PHP_SELF'];
$self = htmlentities($_SERVER['PHP_SELF']); // strip tags to improve security

echo("<table> 
<tr> 
<td> id </td> 
<td>last name</td> 
<td>first name</td> 
<td>delete data</td> 
</tr>");

while($row = mysql_fetch_array($result))
{ 
$id = $row['id'];

echo("<tr>");
        echo("<td>" . $row['id'] . "</td>");
        echo("<td>" . $row['lastName'] . "</td>");
        echo("<td>" . $row['firstName'] . "</td>");
        echo("<td> <form action='$self' method='post'> 
                <input type='hidden' name='delete_id value='$id' /> 
                <input type='submit' value='Delete' />  
            </form> 
        </td>
    </tr>");
}
mysql_free_result($result);
echo("</table>");

}

However this does not work. Does anyone know why. NOTE: I have left my login credentials out but I am connecting to the database elsewhere in the file.

2
  • Just a side note name='delete_id is not well quoted Commented Sep 4, 2012 at 22:39
  • What do you mean by "does not work"? Does it give you an error message? Display a blank screen? Print out the information? Not delete when you click on a button? Delete the wrong record? Commented Sep 4, 2012 at 22:46

2 Answers 2

1

The most probable cause is that your checking for $_POST['Delete'] having not given any of the submit buttons the attribute 'name' of 'Delete'. However, the line you have commented out above should work?

Sign up to request clarification or add additional context in comments.

Comments

0

I think you should look into this areas

//if(isset($_POST['delete_id']) && (!empty($_POST['delete_id']))) 

if(isset($_POST['Delete'])){

and

<input type='submit' value='Delete' />

You should include: <input type='submit' name="Delete" value='Delete' />

That should solve the problem.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.