954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

mysql - problem using delete

Hey
Underneith is my code, im having a problem where as when i click the delete button it does what i need it to do (delete a thead) however it also delete the 'title' fields from every other entry in my database ??

this is substantually weird
can anyone help ??

thankyou in advanced
:

Click me to delete

<?php
if ($_REQUEST['sent'] == 'true') {
$query = "DELETE FROM `forumtutorial_posts` WHERE parentid = '$parentid' OR postid = '$parentid'";
if (mysql_query($query)) {
echo "";
}
else {
echo "";
}
}
?>

Designer_101
Posting Whiz
314 posts since Jul 2007
Reputation Points: 12
Solved Threads: 16
 

pass the auto increment id to the delete command..which is unique in your table...
or post table structure ...
and here what are those parentid and postid...
i think postid is your unique id...???

Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
 

hey
thanks for the reply

yes its the auto increment id that gets stored and then used as a rope to delete the thread, and all the posts inside.

parent id is all of the posts in a thread. so if my threads postid was 1 all the posts in it would have a parent id of 1.
and the post id is simply the auto increment

i hope you can help
thans in advanced

Designer_101
Posting Whiz
314 posts since Jul 2007
Reputation Points: 12
Solved Threads: 16
 

so,you wan to delete only that post,then simple use:

$query = "DELETE FROM `forumtutorial_posts` WHERE postid = '$parentid'";

i don't know, why you are writing the below line..could you please tel me what is the reason behind that line... parentid = '$parentid' OR

or if you want to recognize both parentid and postid then use AND instead of OR.

Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
 

heyy1

i've found the problem

<?php
$parentid = $_REQUEST['delid'];
echo $parentid;
?>
<a href='delete.php?sent=true' style="margin-left:60px; font-size:14px; color:#FF0000;"><b>Click me to delete</b></a>

<?php
if ($_REQUEST['sent'] == 'true') {
$query = "DELETE FROM `forumtutorial_posts` WHERE parentid = '8' OR postid = '8'";
if (mysql_query($query)) {
echo "<script>alert('Topic Deleted'); location.href = 'members.php'; </script>";
}
else {
echo "<script>alert('Something Went Wrong, Contact Reece Stanton'); location.href = 'members.php'; </script>";
}
}   
	?>

i echod the parentid and it holds this:
?id=12

instead of this:
12

im sure this is just a simple problem
any ideas?

thanks

Designer_101
Posting Whiz
314 posts since Jul 2007
Reputation Points: 12
Solved Threads: 16
 

heyy

all its doing is deleing the post that has an postid of '12' and any other posts that parent is post '12' (parentid).
or if you want to recognize both parentid and postid then use AND instead of OR.

I have to use OR because im looking for anything with either a postid or a parent id of '12'.
If i was searching for both, it would only find the parent post, everything inside wouldnt be deleted.

I hope you understand, look at my post above i think thats the problem.

Designer_101
Posting Whiz
314 posts since Jul 2007
Reputation Points: 12
Solved Threads: 16
 

hey
thanks for your help
but its solved

it was a url parse error lol

thanks again

Designer_101
Posting Whiz
314 posts since Jul 2007
Reputation Points: 12
Solved Threads: 16
 

hey thanks for your help but its solved

it was a url parse error lol

thanks again


ok.......

Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You