Jump to content


Photo

Help with mysql DELTE FROM table id='$id';


  • Please log in to reply
16 replies to this topic

#1 cameeob2003

cameeob2003
  • Members
  • PipPipPip
  • Advanced Member
  • 79 posts

Posted 07 July 2006 - 12:57 AM

I am having trouble getting this to work when ever I try to have the following script run:

if($_GET['act'] == "delete_recent_match"){
	
	$id = $_GET["edit_recent_match2"];
    $query = "DELETE FROM recent_match WHERE id='$id'";
	mysql_query($query) or die (mysql_error());
	
	if(!$query){
	echo '<font id=UserNameRed />There has been an error deleting the data. Please contact the 	webmaster.';
	}else{
	echo '<font id=UserNameRed />The data was deleted successfully.';
	}
}

I get this in the browser address:

http://mysite.com/delete_recent_match_proc.php?delete_recent_match=1&submit=submit


I know its because this page is on the same page as the file from where in trying to execute it but why does it go to the "&submit=submit" line?? Im not sure of what I should do to correct this.

#2 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 07 July 2006 - 01:05 AM

I am having trouble getting this to work when ever I try to have the following script run:

if($_GET['act'] == "delete_recent_match"){
	
	$id = $_GET["edit_recent_match2"];
    $query = "DELETE FROM recent_match WHERE id='$id'";
	mysql_query($query) or die (mysql_error());
	
	if(!$query){
	echo '<font id=UserNameRed />There has been an error deleting the data. Please contact the 	webmaster.';
	}else{
	echo '<font id=UserNameRed />The data was deleted successfully.';
	}
}

I get this in the browser address:

http://mysite.com/delete_recent_match_proc.php?delete_recent_match=1&submit=submit


I know its because this page is on the same page as the file from where in trying to execute it but why does it go to the "&submit=submit" line?? Im not sure of what I should do to correct this.


"if($_GET['act'] == "delete_recent_match")"  you need to make the address http://mysite.com/de...recent_match... also i would make the code like......
if($_GET['act'] == "delete_recent_match"){
	
	$id = $_GET["edit_recent_match2"];
    $query = mysql_query("DELETE FROM recent_match WHERE id='$id'") or die (mysql_error());
	
	if(!$query){
	echo '<font id=UserNameRed />There has been an error deleting the data. Please contact the 	webmaster.';
	}else{
	echo '<font id=UserNameRed />The data was deleted successfully.';
	}
}
then you would go to that page in the format of http://yoursite.com/...nt_match2=<this would be the $id variable in your script>
Why doesn't anyone ever say hi, hey, or whad up world?

#3 cameeob2003

cameeob2003
  • Members
  • PipPipPip
  • Advanced Member
  • 79 posts

Posted 07 July 2006 - 02:13 AM

Would I set it in that way by the following:

if($_GET['act'] == "edit_matches&delete_recent_match"){
	
	$id = $_GET["edit_recent_match2"];
    $query = mysql_query("DELETE FROM recent_match WHERE id='$id'") or die (mysql_error());
	
	if(!$query){
	echo '<font id=UserNameRed />There has been an error deleting the data. Please contact the 	webmaster.';
	}else{
	echo '<font id=UserNameRed />The data was deleted successfully.';
	}
}


#4 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 07 July 2006 - 02:24 AM

$_GET['act'] == "edit_matches&delete_recent_match" would mean it would have to be http://yousite.com/y...te_recent_match, but php interpets & as seperating get variables so that wouldnt work...
Why doesn't anyone ever say hi, hey, or whad up world?

#5 cameeob2003

cameeob2003
  • Members
  • PipPipPip
  • Advanced Member
  • 79 posts

Posted 07 July 2006 - 03:03 AM

Well what format would I put it in since im not realy that great at php and in a rush tofinish this section?

#6 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 07 July 2006 - 03:28 AM

i would use a code like
if($_GET['act'] == "del"){
	
	$id = $_GET["id"];
    $query = mysql_query("DELETE FROM recent_match WHERE id='$id'") or die (mysql_error());
	
	if(!$query){
	echo '<font id=UserNameRed />There has been an error deleting the data. Please contact the 	webmaster.';
	}else{
	echo '<font id=UserNameRed />The data was deleted successfully.';
	}
}
and call to it with something like http://site.com/page...ct=del&id=<what you want $id to be>
Why doesn't anyone ever say hi, hey, or whad up world?

#7 cameeob2003

cameeob2003
  • Members
  • PipPipPip
  • Advanced Member
  • 79 posts

Posted 07 July 2006 - 04:11 AM

So how do I get the:

"page.php?act=del&id="
portion to add the &id= part? Im not realy sure of this an explination or tutorial area on this would be great I would google it but im not sure how to define it.

#8 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 07 July 2006 - 04:33 AM

Well what is making the URL?
Why doesn't anyone ever say hi, hey, or whad up world?

#9 cameeob2003

cameeob2003
  • Members
  • PipPipPip
  • Advanced Member
  • 79 posts

Posted 07 July 2006 - 05:02 AM

edit_match.php is making the file

#10 cameeob2003

cameeob2003
  • Members
  • PipPipPip
  • Advanced Member
  • 79 posts

Posted 07 July 2006 - 08:48 AM

I am not sure why this wont delete the actuall posting from the mysql database I have reviewed several websites and different forums to find the answer to my knowldge it is as it should be. The only problem is when I go to delete the post it says deleted and will not delete the post. Here is the code im using to do so:

<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>n2p - Nothing to Prove</title>
<link rel="stylesheet" href="n2p.css" type="text/css" />
</head>

<body>
<?php
	include("db.php");
	if($_GET['act'] == "delete"){
//include database files

	$id = $_GET['delete_news'];
	$sql = mysql_query("DELETE FROM news WHERE id='$id'") or die (mysql_error());
	
	if(!sql){
		echo "Could not delete news post.";
	}else{
		echo "News post deleted.";
	}
}
?>
<form method="post" name="delete_old_news" action="?act=delete">
<table>
<tr>
<td>
<select name="news_posts">
<?php
// Delete Highlight Match

							$sql = "SELECT * FROM `news` order by `id`";
							$result  = mysql_query($sql) or die(mysql_error());
							while ($text = mysql_Fetch_array($result)) {
											$id = $text['id'];
											$title = $text['title'];
											$ndate = $text['date'];
											
											echo '<option name="delete_news" value="'.$id.'">'. $title .' '. $ndate .'</option><br/>';}

?>
</select>
</td>
</tr>
<td><input name="submit" type="submit" value="submit" /></td></tr>
</table>
</form>
</body>
</html>

If someone could explain why this isnt working to me that would be great im realy wanting to learn the reson why.

#11 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 07 July 2006 - 08:54 AM

-.-! You already had a same thread, why are you creating a new one ?

Btw.. From your script, you can delete the news by going to http://domain/file.p...e&delete_news=1
Then your news id 1 should be deleted.

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#12 cameeob2003

cameeob2003
  • Members
  • PipPipPip
  • Advanced Member
  • 79 posts

Posted 07 July 2006 - 08:58 AM

sorry im just looking for an explination on how to get this to work were it goes to http://domain/file.p...e&delete_news=1 instead of the not functioning -.^

#13 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 07 July 2006 - 09:07 AM

Have you tried going to the link above ?
Does it works ?

Btw.. Remember to change domain to your site URL.

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#14 Zane

Zane
  • Administrators
  • Advanced Member
  • 4,134 posts

Posted 07 July 2006 - 09:08 AM

<form method="post" name="delete_old_news" action="?act=delete">
because your form is meant to POST not to GET

which is what array you're looking for

btn_donate_SM.gif Want to thank me? Contribute to my PayPal piggy-bank
 

172938.png

#15 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 07 July 2006 - 09:10 AM

What about the scripts he put:
<?php
	include("db.php");
	if($_GET['act'] == "delete"){
//include database files

	$id = $_GET['delete_news'];
	$sql = mysql_query("DELETE FROM news WHERE id='$id'") or die (mysql_error());
	
	if(!sql){
		echo "Could not delete news post.";
	}else{
		echo "News post deleted.";
	}
}
?>

He could access that code by going to the link. Am I right ?

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#16 Zane

Zane
  • Administrators
  • Advanced Member
  • 4,134 posts

Posted 07 July 2006 - 09:14 AM

He could access that code by going to the link. Am I right ?


your right...but he's wanting the button to acces it though....dynamically

btn_donate_SM.gif Want to thank me? Contribute to my PayPal piggy-bank
 

172938.png

#17 cameeob2003

cameeob2003
  • Members
  • PipPipPip
  • Advanced Member
  • 79 posts

Posted 07 July 2006 - 09:23 AM

Yes and im not sure where or how I would go about this. I want to click the button and have it add the $id to the end automatically.

Im sorry I may be annoying but its just I realy want to learn this stuff I find it fun and enjoyable.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users