cameeob2003 Posted July 7, 2006 Share Posted July 7, 2006 I am having trouble getting this to work when ever I try to have the following script run:[code]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.'; }}[/code]I get this in the browser address:[quote]http://mysite.com/delete_recent_match_proc.php?delete_recent_match=1&submit=submit[/quote]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. Quote Link to comment https://forums.phpfreaks.com/topic/13912-help-with-mysql-delte-from-table-idid/ Share on other sites More sharing options...
corbin Posted July 7, 2006 Share Posted July 7, 2006 [quote author=cameeob2003 link=topic=99736.msg392877#msg392877 date=1152233839]I am having trouble getting this to work when ever I try to have the following script run:[code]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.'; }}[/code]I get this in the browser address:[quote]http://mysite.com/delete_recent_match_proc.php?delete_recent_match=1&submit=submit[/quote]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.[/quote]"if($_GET['act'] == "delete_recent_match")" you need to make the address http://mysite.com/delete_recent_match_proc.php?delete_recent_match=1&submit=submit&act=delete_recent_match... also i would make the code like......[code]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.'; }}[/code]then you would go to that page in the format of http://yoursite.com/page.php?act=delete_recent_match&edit_recent_match2=<this would be the $id variable in your script> Quote Link to comment https://forums.phpfreaks.com/topic/13912-help-with-mysql-delte-from-table-idid/#findComment-54186 Share on other sites More sharing options...
cameeob2003 Posted July 7, 2006 Author Share Posted July 7, 2006 Would I set it in that way by the following:[code] 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.'; }}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/13912-help-with-mysql-delte-from-table-idid/#findComment-54202 Share on other sites More sharing options...
corbin Posted July 7, 2006 Share Posted July 7, 2006 $_GET['act'] == "edit_matches&delete_recent_match" would mean it would have to be http://yousite.com/yourpage.php?act=editmatches&delete_recent_match, but php interpets & as seperating get variables so that wouldnt work... Quote Link to comment https://forums.phpfreaks.com/topic/13912-help-with-mysql-delte-from-table-idid/#findComment-54204 Share on other sites More sharing options...
cameeob2003 Posted July 7, 2006 Author Share Posted July 7, 2006 Well what format would I put it in since im not realy that great at php and in a rush tofinish this section? Quote Link to comment https://forums.phpfreaks.com/topic/13912-help-with-mysql-delte-from-table-idid/#findComment-54213 Share on other sites More sharing options...
corbin Posted July 7, 2006 Share Posted July 7, 2006 i would use a code like [code]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.'; }}[/code] and call to it with something like http://site.com/page.php?act=del&id=<what you want $id to be> Quote Link to comment https://forums.phpfreaks.com/topic/13912-help-with-mysql-delte-from-table-idid/#findComment-54219 Share on other sites More sharing options...
cameeob2003 Posted July 7, 2006 Author Share Posted July 7, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/13912-help-with-mysql-delte-from-table-idid/#findComment-54227 Share on other sites More sharing options...
corbin Posted July 7, 2006 Share Posted July 7, 2006 Well what is making the URL? Quote Link to comment https://forums.phpfreaks.com/topic/13912-help-with-mysql-delte-from-table-idid/#findComment-54230 Share on other sites More sharing options...
cameeob2003 Posted July 7, 2006 Author Share Posted July 7, 2006 edit_match.php is making the file Quote Link to comment https://forums.phpfreaks.com/topic/13912-help-with-mysql-delte-from-table-idid/#findComment-54231 Share on other sites More sharing options...
cameeob2003 Posted July 7, 2006 Author Share Posted July 7, 2006 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:[code]<?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>[/code]If someone could explain why this isnt working to me that would be great im realy wanting to learn the reson why. Quote Link to comment https://forums.phpfreaks.com/topic/13912-help-with-mysql-delte-from-table-idid/#findComment-54283 Share on other sites More sharing options...
hackerkts Posted July 7, 2006 Share Posted July 7, 2006 -.-! 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.php?act=delete&delete_news=1Then your news id 1 should be deleted. Quote Link to comment https://forums.phpfreaks.com/topic/13912-help-with-mysql-delte-from-table-idid/#findComment-54286 Share on other sites More sharing options...
cameeob2003 Posted July 7, 2006 Author Share Posted July 7, 2006 sorry im just looking for an explination on how to get this to work were it goes to [url=http://domain/file.php?act=delete&delete_news=1]http://domain/file.php?act=delete&delete_news=1[/url] instead of the not functioning -.^ Quote Link to comment https://forums.phpfreaks.com/topic/13912-help-with-mysql-delte-from-table-idid/#findComment-54288 Share on other sites More sharing options...
hackerkts Posted July 7, 2006 Share Posted July 7, 2006 Have you tried going to the link above ?Does it works ?Btw.. Remember to change domain to your site URL. Quote Link to comment https://forums.phpfreaks.com/topic/13912-help-with-mysql-delte-from-table-idid/#findComment-54291 Share on other sites More sharing options...
Zane Posted July 7, 2006 Share Posted July 7, 2006 [code]<form method="post" name="delete_old_news" action="?act=delete">[/code]because your form is meant to POST not to GETwhich is what array you're looking for Quote Link to comment https://forums.phpfreaks.com/topic/13912-help-with-mysql-delte-from-table-idid/#findComment-54292 Share on other sites More sharing options...
hackerkts Posted July 7, 2006 Share Posted July 7, 2006 What about the scripts he put:[code]<?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."; }}?>[/code]He could access that code by going to the link. Am I right ? Quote Link to comment https://forums.phpfreaks.com/topic/13912-help-with-mysql-delte-from-table-idid/#findComment-54294 Share on other sites More sharing options...
Zane Posted July 7, 2006 Share Posted July 7, 2006 [quote author=hackerkts link=topic=99761.msg392995#msg392995 date=1152263436]He could access that code by going to the link. Am I right ?[/quote]your right...but he's wanting the button to acces it though....dynamically Quote Link to comment https://forums.phpfreaks.com/topic/13912-help-with-mysql-delte-from-table-idid/#findComment-54296 Share on other sites More sharing options...
cameeob2003 Posted July 7, 2006 Author Share Posted July 7, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/13912-help-with-mysql-delte-from-table-idid/#findComment-54300 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.