Jump to content

deleting and editing table entities


lesolemph

Recommended Posts

table.jpg

the above/attached image shows a table outputted using a 'for loop', it has the action column that should either edit or delete entity...

I need help to be able to edit or delete each entity by clicking the action link...

 

find attached image...

 

[attachment deleted by admin]

Link to comment
Share on other sites

Need to make a php file called delete.php, inside this file is a POST form and value unique to that row,I personally use id because should only be one id. using names and such there could be multiples. So the POST value should be coming from your display page.

 

I do something like this, and this is hard for me to explain fully.

 

I made a .php file that does the connect to database that references the posts unique id from a GET in a hyperlink. I use GET versus POST because I use it many places throughout my site. All my admin hyperlinks for functions target a new window and javascript code at the end with window.close. My admin functions are protected by admin user sessions to be able to execute the action. If not admin it redirects them with header back to the main site url.

 

The php file is located in the same directory so just referencing the php file.

<a href='delete-id.php?theid=$post_id'> [ Delete Post ] </a>

 

inside delete-id.php will be a form, the value is theid, in the hyperlink above it uses $post_id to discover it's value from the post.

 

<form action="delete-id.php" method="get">

 

<p>Post ID : <input type="text" name="theid"  value="" class="text" style="width:30px; height:25px;" /> <input type="submit" value="Delete" class="button" style="width:20px; height:30px;" /></p>

</form>

 

 

delete-id.php

<?php
$id = $_GET['theid'];
$connect = mysql_connect('localhost', 'user', 'password');
mysql_select_db('databasename');
mysql_query("DELETE FROM table WHERE id = ('$id')");
mysql_close($connect); 
}

?>

 

The php file is located in the same directory so just referencing the php file.

<a href='delete-id.php?theid=$post_id'> [ Delete Post ] </a>

 

 

I attached a text file that could rename to just .php extension and modify to your needs.

My way is just a different way of doing this, you can just do POST and from the same page and form. Depends what you need to do with it, any checking, how it gets called upon and so on.

 

Hope this helps.

 

[attachment deleted by admin]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.