Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Oct 2010
    Thanked 0 Times in 0 Posts

    Wont delete table row by ID

    So I have my site almost all setup, except I want to allow users the ability to delete data from their games.

    So I have it setup where their data is one one page, listed via looping. Under each, their is a delete button which looks like this:

    echo "<a href=\"delete_game.php?id=" . $index . "\">Delete</a>";
    So ive got it working fine the $index variable is being pulled down, and transferred to the delete_game page.

    On the delete game page I say "Do you really want to delete this game"

    Then wrote:

    if(isset($_POST['yes'])) {
    	$query = mysql_query("DELETE FROM games WHERE index='$index'");
    	if($query) {
    	echo "The game has been deleted";
    	} else {
    	echo "The game could not be deleted";
    Every single time it says "the game could not be deleted" I have tried it since by trying to the delete the row by a different variable and it works.

    So the issue is $index is my auto increment primary key, but it wont let me delete by it, so how do I do this?

    Or do I really need to pass each and every unique variable from page to page, and do it that way?

    Help is greatly appreciated.


  2. #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Thanked 2,250 Times in 2,237 Posts
    echo "<a href=\"delete_game.php?id=" . $index . "\">Delete</a>";
    if(isset($_POST['yes'])) {
    A value passed via url will be inside the global array $_GET, and so you must look for $_GET['id']

    PS: You must validate the id to make sure that the user has the right privilege to delete a particular entry from table.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts