Jump to content

Archived

This topic is now archived and is closed to further replies.

cameeob2003

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

Recommended Posts

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.

Share this post


Link to post
Share on other sites
[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>

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
$_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...

Share this post


Link to post
Share on other sites
Well what format would I put it in since im not realy that great at php and in a rush tofinish this section?

Share this post


Link to post
Share on other sites
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>

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
-.-! 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=1
Then your news id 1 should be deleted.

Share this post


Link to post
Share on other sites
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 -.^

Share this post


Link to post
Share on other sites
Have you tried going to the link above ?
Does it works ?

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

Share this post


Link to post
Share on other sites
[code]<form method="post" name="delete_old_news" action="?act=delete">[/code]
because your form is meant to POST not to GET

which is what array you're looking for

Share this post


Link to post
Share on other sites
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 ?

Share this post


Link to post
Share on other sites
[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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.