Jump to content


Photo

Deleting a post


  • Please log in to reply
8 replies to this topic

#1 Chris Coin

Chris Coin
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 03 April 2006 - 12:22 AM

is ther a way to delete a post, posted to another php file

Example: "index.php" post to "info.php"

id like the "info.php" to display somthing like this:

name: (name)
link: (link)
description: (description)
[!--coloro:#CC0000--][span style=\"color:#CC0000\"][!--/coloro--]Delete this link[!--colorc--][/span][!--/colorc--] <---this would be a link that would delete the above lines and the only above lines, because ther will be info before and after it.

is somthin like this possible?

#2 realjumper

realjumper
  • Members
  • PipPipPip
  • Advanced Member
  • 399 posts

Posted 03 April 2006 - 01:57 AM

The 'Delete this link' just has to have the id variable of the record in the url....like for example
echo "<a href=\"delete.php?id=$id\">Delete this link</a>";

and on the delete.php page

$id=$_GET['id'];

mysql_query("DELETE FROM your table WHERE id=$id");


#3 Chris Coin

Chris Coin
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 03 April 2006 - 10:27 PM

[!--quoteo(post=361071:date=Apr 2 2006, 08:57 PM:name=realjumper)--][div class=\'quotetop\']QUOTE(realjumper @ Apr 2 2006, 08:57 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
The 'Delete this link' just has to have the id variable of the record in the url....like for example
echo "<a href=\"delete.php?id=$id\">Delete this link</a>";

and on the delete.php page

$id=$_GET['id'];

mysql_query("DELETE FROM your table WHERE id=$id");
[/quote]

thanks alot,

but i dont know if this will work, because when "submit.php" post to "info.php" it will create the same id for each post , then the delete link will delete all the post with same id,

am i right?


#4 realjumper

realjumper
  • Members
  • PipPipPip
  • Advanced Member
  • 399 posts

Posted 03 April 2006 - 11:08 PM

I'm assuming that on info.php you will have a list like....

name: (whatever)
link: (whatever)
description: (whatever)
Delete this link

name: (foo)
link: (foo)
description: (foo)
Delete this link

name: (stuff)
link: (stuff)
description: (stuff)
Delete this link

If so.....this information will come from a select query. Something like...
$result = mysql_query("SELECT name,link,description,id FROM table") 
or die(mysql_error());

echo "<table>";

while(list($name, $link, $description, $id)=mysql_fetch_array($result)){


        echo "<tr>";
        echo "<td>$name</td></tr>";
        echo "<tr><td>$link</td></tr>";
        echo "<tr><td>$description</td></tr>";
        echo "<tr><td><a href=\"delete.php?id=$id\">Delete This Link</a></td></tr>";
        }

echo "</table>";
....the above should do it

#5 Chris Coin

Chris Coin
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 03 April 2006 - 11:11 PM

[!--quoteo(post=361388:date=Apr 3 2006, 06:08 PM:name=realjumper)--][div class=\'quotetop\']QUOTE(realjumper @ Apr 3 2006, 06:08 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I'm assuming that on info.php you will have a list like....

name: (whatever)
link: (whatever)
description: (whatever)
Delete this link

name: (foo)
link: (foo)
description: (foo)
Delete this link

name: (stuff)
link: (stuff)
description: (stuff)
Delete this link

If so.....this information will come from a select query. Something like...
$result = mysql_query("SELECT name,link,description,id FROM table") 
or die(mysql_error());

echo "<table>";

while(list($name, $link, $description, $id)=mysql_fetch_array($result)){
        echo "<tr>";
        echo "<td>$name</td></tr>";
        echo "<tr><td>$link</td></tr>";
        echo "<tr><td>$description</td></tr>";
        echo "<tr><td><a href=\"delete.php?id=$id\">Delete This Link</a></td></tr>";
        }

echo "</table>";
....the above should do it
[/quote]

Yeah this is perfect.

is ther a way to do the same thing if i was posting to a flat file?


#6 realjumper

realjumper
  • Members
  • PipPipPip
  • Advanced Member
  • 399 posts

Posted 03 April 2006 - 11:24 PM

A flat file.....hmmm...I could be wrong but I very much doubt it because the id is the unique identifier, which is incremented by one every time a new record is inserted in the db....something a flat file cannot do automatically.

#7 Chris Coin

Chris Coin
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 03 April 2006 - 11:30 PM

[!--quoteo(post=361393:date=Apr 3 2006, 06:24 PM:name=realjumper)--][div class=\'quotetop\']QUOTE(realjumper @ Apr 3 2006, 06:24 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
A flat file.....hmmm...I could be wrong but I very much doubt it because the id is the unique identifier, which is incremented by one every time a new record is inserted in the db....something a flat file cannot do automatically.
[/quote]

thats what i thought, but i just wanted to make sure.

it wouldnt work because when you would press the delete link, since the form would submit the same id to all post then it would delete all the post in the flat file.

am i right?

unless ther is away to make a script that would give out random numbers as the id, but i gess random isnt so random somtimes so maybe eventually you might delete more then one post.

#8 realjumper

realjumper
  • Members
  • PipPipPip
  • Advanced Member
  • 399 posts

Posted 03 April 2006 - 11:37 PM

I'm sure if you got creative and put on your thinking cap it could be done.....but it's simple when using a database rather than a flat file, so being a lazy person I choose the database every time!! :-)

#9 Chris Coin

Chris Coin
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 03 April 2006 - 11:39 PM

[!--quoteo(post=361397:date=Apr 3 2006, 06:37 PM:name=realjumper)--][div class=\'quotetop\']QUOTE(realjumper @ Apr 3 2006, 06:37 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I'm sure if you got creative and put on your thinking cap it could be done.....but it's simple when using a database rather than a flat file, so being a lazy person I choose the database every time!! :-)
[/quote]

haha i hear what your saying,
im goin to try with a flat file and see if i can come up with somthing....
Thanks for all the help.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users