Jump to content

creating a function and using it in a link to delete a record


dazz_club

Recommended Posts

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

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;

}

 

 

}

 

 

Archived

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

×
×
  • 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.