Page 1 of 1

deletion on the same page

Posted: Fri Mar 26, 2004 12:11 am
by crimsonluv
Hai ! i wanted to delete a record from database on the same page . but i can only delete it if i click twice on the link ? why?
here are my codes

<head>
<script type="text/javascript">
function delete() {
<?php $dblink=mysql_connect("localhost","root");

mysql_select_db("database",$dblink) or die("no connection") ;
$query=mysql_query("DELETE FROM Staffs_Category WHERE category_name='$id'" , $dblink);
?>
}
</script>
</head>
<body onload = "delete()">
<table><tr>
<td><a href = "staff.php?id=<?php echo $row->category_name?>">delete</a></td>
</tr>
</table>



thanks for helping :)

Posted: Fri Mar 26, 2004 12:29 am
by PrObLeM
just make a diffent page to link to like delete.php
this is just 1 possibility there are plenty of ways todo it

( i would do it alittle differently but im just keeping it in the same basic style you have)

Code: Select all

<?php
//this is what delete.php should look like
 mysql_select_db("database",$dblink) or die("no connection") ;
$query=mysql_query("DELETE FROM Staffs_Category WHERE category_name='".$_GET['id']."'" , $dblink); 
echo 'category deleted';
//or
//header('Location: index.php');
?>
staff.php

Code: Select all

&lt;body&gt;
&lt;table&gt;&lt;tr&gt;
&lt;td&gt;&lt;a href = "delete.php?id=&lt;?php echo $row-&gt;category_namen ?&gt;"&gt;delete&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;

Posted: Fri Mar 26, 2004 12:43 am
by crimsonluv
how is it if i don't want to delete the record in delete.php?

i want it to happen on the same page(staff.php). a page show a list of staff and when i click delete on one of the staff name, the staff will be deleted and the page will not show the record anymore

:)

Posted: Fri Mar 26, 2004 12:48 am
by PrObLeM
then have it just redirect back to the staff page and then it will be refeshed and it wont show the record anymore

Posted: Fri Mar 26, 2004 1:03 am
by crimsonluv
i was trying to do that with the codes i put up above. but i dunno it's correct or not :( the record can only be deleted when i clicked on the link twice
i'm a bit slow in catching up. so bear with me. hehe