dazz_club Posted April 17, 2008 Share Posted April 17, 2008 Hi all, I have created a function that deletes a record by using ID, I am now trying to use this function in the link but im running into some trouble. Here is the function; //these functions on this page will be exported out to a function outsource when i get the time function delete_order(){ if ( (isset($_GET['ID'])) && (is_numeric($_GET['ID'])) ) { //correctly accessed $id=$_GET['ID']; } else { $errors[] = 'You have accessed this page incorrectly.'; } $query = "DELETE FROM order_enquiries WHERE id =$id"; $return = mysql_query($query); echo "File ID $id has been removed from the database"; } and here is the link i am trying to put the function in; <a href=\"<?php echo delete_order(); ?>\" >DELETE CONTACT</a> kind regards Dazzclub Link to comment https://forums.phpfreaks.com/topic/101556-creating-a-function-and-using-it-in-a-link-to-delete-a-record/ Share on other sites More sharing options...
BobcatM Posted April 17, 2008 Share Posted April 17, 2008 What trouble is it you are running into? Link to comment https://forums.phpfreaks.com/topic/101556-creating-a-function-and-using-it-in-a-link-to-delete-a-record/#findComment-519457 Share on other sites More sharing options...
mofm Posted April 17, 2008 Share Posted April 17, 2008 Try somthing like this <a href="delete.php?ID=3" >DELETE CONTACT</a> delete.php?ID=3 delete.php is the file your funtion is stored on ?ID=3 is the id of teh row you are deleting doing it this way you will need to remove funtion funtionname { } uif you need to keep it in a function for what ever reason make a new page and do somthing like this include 'functions.php'; $id=$_GET['ID'] //ofcourse sqlinjection etc needs adding if(delete_order($id)==1) {echo "rowdeleted"}else{echo "error occured or invalid id";} the function would look somthing like function delete_order($ID) { $query = "DELETE FROM order_enquiries WHERE id =$ID"; if($return = mysql_query($query)) { return 1; }else{ return 0; } } Link to comment https://forums.phpfreaks.com/topic/101556-creating-a-function-and-using-it-in-a-link-to-delete-a-record/#findComment-519461 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.