Jump to content

Archived

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

Chris Coin

Deleting a post

Recommended Posts

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?

Share this post


Link to post
Share on other sites
The 'Delete this link' just has to have the id variable of the record in the url....like for example
[code]
echo "<a href=\"delete.php?id=$id\">Delete this link</a>";
[/code]

and on the delete.php page

[code]
$id=$_GET['id'];

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

Share this post


Link to post
Share on other sites
[!--quoteo(post=361071:date=Apr 2 2006, 08:57 PM:name=realjumper)--][div class=\'quotetop\']QUOTE(realjumper @ Apr 2 2006, 08:57 PM) [snapback]361071[/snapback][/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
[code]
echo "<a href=\"delete.php?id=$id\">Delete this link</a>";
[/code]

and on the delete.php page

[code]
$id=$_GET['id'];

mysql_query("DELETE FROM your table WHERE id=$id");
[/code]
[/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?

Share this post


Link to post
Share on other sites
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...
[code]
$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>";
[/code]
....the above should do it

Share this post


Link to post
Share on other sites
[!--quoteo(post=361388:date=Apr 3 2006, 06:08 PM:name=realjumper)--][div class=\'quotetop\']QUOTE(realjumper @ Apr 3 2006, 06:08 PM) [snapback]361388[/snapback][/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...
[code]
$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>";
[/code]
....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?

Share this post


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

Share this post


Link to post
Share on other sites
[!--quoteo(post=361393:date=Apr 3 2006, 06:24 PM:name=realjumper)--][div class=\'quotetop\']QUOTE(realjumper @ Apr 3 2006, 06:24 PM) [snapback]361393[/snapback][/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.

Share this post


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

Share this post


Link to post
Share on other sites
[!--quoteo(post=361397:date=Apr 3 2006, 06:37 PM:name=realjumper)--][div class=\'quotetop\']QUOTE(realjumper @ Apr 3 2006, 06:37 PM) [snapback]361397[/snapback][/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.

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.