ozzie135 Posted September 4, 2007 Share Posted September 4, 2007 I am quite new to php and am writing an application that needs to be able to delete users from the database. To do this I am extracting all users from the database and echoing them to the page in a HTML table with two columns. The first is the username and the second is an image representing the delete operation (ie. the user clicks the delete image and the user should be deleted from the database). I am quite unsure as to how to go about this? Is the best way to add an onclick() function to each image and pass the username as a querystring to the deletecoontact.php page? The code below might explain this better: <IMG src="images/delete.png" onclick="window.open('deletecontact.php?id=<?=$username?>','newwindow','width=560,height=400')" name="submit"> Is this the best way to do it, or is there a more simple way of handling the onclick event? Any help would be greatfully received. Quote Link to comment https://forums.phpfreaks.com/topic/67894-deleting-contacts/ Share on other sites More sharing options...
Ninjakreborn Posted September 4, 2007 Share Posted September 4, 2007 In the db make sure there's an auto-inc ID field. Then when you are echoing your names, have a linkor button beside them goign to a delete page. Send the ID to it, then get the id with php, and use that id to delete that record. Quote Link to comment https://forums.phpfreaks.com/topic/67894-deleting-contacts/#findComment-341275 Share on other sites More sharing options...
ozzie135 Posted September 4, 2007 Author Share Posted September 4, 2007 Thats a great idea. The only issue I have is how do I then refresh the list page (the page with all the users on with the associated delete image)? So that the user clicks on the delete image, the php code will then delete the user (from their id) and then the list page should refresh to reflect those changes (ie. the list minus the deleted user). This seems to be the biggest issue. Thanks again for the quick reply mate. Quote Link to comment https://forums.phpfreaks.com/topic/67894-deleting-contacts/#findComment-341285 Share on other sites More sharing options...
Ninjakreborn Posted September 4, 2007 Share Posted September 4, 2007 You are going to need to learn enough ajax to accomplish that, ajax is what will do something like that. Quote Link to comment https://forums.phpfreaks.com/topic/67894-deleting-contacts/#findComment-341345 Share on other sites More sharing options...
ozzie135 Posted September 4, 2007 Author Share Posted September 4, 2007 I know Ajax, just not really well with php. Just wanted a quick solution, but I think you may be right, Ajax will be better for this. Quote Link to comment https://forums.phpfreaks.com/topic/67894-deleting-contacts/#findComment-341355 Share on other sites More sharing options...
Ninjakreborn Posted September 4, 2007 Share Posted September 4, 2007 www.w3schools.com they just recently added tutorials UNDER php about ajax. Specifically geared towards using ajax inside of php. Quote Link to comment https://forums.phpfreaks.com/topic/67894-deleting-contacts/#findComment-341454 Share on other sites More sharing options...
ozzie135 Posted September 5, 2007 Author Share Posted September 5, 2007 Thanks for the reply, I understand what technologies to use, its the correct usage of them that I am unsure of. Is the image tag the best way to do it i.e. <INPUT TYPE="image" src="images/delete.gif" onclick="removeuser() " name="submit"> Then the remove user function by posting the userid in the querystring using javascript (AJAX)? I will still have the problem of actually removing the user from the table. Quote Link to comment https://forums.phpfreaks.com/topic/67894-deleting-contacts/#findComment-342049 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.