lesolemph Posted November 25, 2010 Share Posted November 25, 2010 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] Quote Link to comment https://forums.phpfreaks.com/topic/219810-deleting-and-editing-table-entities/ Share on other sites More sharing options...
QuickOldCar Posted November 25, 2010 Share Posted November 25, 2010 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] Quote Link to comment https://forums.phpfreaks.com/topic/219810-deleting-and-editing-table-entities/#findComment-1139620 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.