Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-17-2010, 07:15 AM   PM User | #1
totesmagotes
New Coder

 
Join Date: Oct 2010
Posts: 31
Thanks: 2
Thanked 0 Times in 0 Posts
totesmagotes is an unknown quantity at this point
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:

Code:
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:

Code:
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.

Thanks
totesmagotes is offline   Reply With Quote
Old 12-17-2010, 09:51 AM   PM User | #2
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,678
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Quote:
echo "<a href=\"delete_game.php?id=" . $index . "\">Delete</a>";
Quote:
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.
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:32 AM.


Advertisement
Log in to turn off these ads.