Forum Moderators: coopster

Message Too Old, No Replies

Deleting Rows from DataBase

How to get confirmation wheather or not to delete row from database.

         

Saboi

7:36 am on Mar 14, 2007 (gmt 0)

10+ Year Member



Hi guys,

I have written a script that deletes specified rows from my sql database.I use an html front page where i enter the name of the individual i would like to remove from the database.This works fine.However i would like it to confirm with me wheather or not the action should take place using a dialog box.How best can i do that?Any scrips in mind? Please assist....

omoutop

8:47 am on Mar 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Welcome to webmasterworld Saboi.

There are a couple of ways to accomplish what you want.

A) with php you send your user to a new page where you ask fo confirmation and proceed
B) with javascript when he presses the submit button

joelgreen

3:47 pm on Mar 14, 2007 (gmt 0)

10+ Year Member



with javascript when he presses the submit button

FYI: function name is prompt

Scally_Ally

5:04 pm on Mar 14, 2007 (gmt 0)

10+ Year Member



omoutop's suggestion B works well for me.

Add this onclick script (whether it be on a link or a submit button, as it will execute the onclick first).

onClick="javascript:return confirm('do you really want to delete this item?')"

Hope this helps

Ally

[edited by: Scally_Ally at 5:06 pm (utc) on Mar. 14, 2007]

elgumbo

5:09 pm on Mar 14, 2007 (gmt 0)

10+ Year Member



On a related issue, I actually stopped users from being able to delete anything from the database. I just add another field called SHOW to the table and toggle it between ON and OFF.

As far as the user is concerned, when they "Delete" something it goes. But it's much easier for me to "Undelete" it when they realise they've made a mistake and want the data back.

omoutop

7:12 am on Mar 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



elgumbo is correct... never trust a user. Better to follow his advice and "hide" content than delete it.
Once per week, check the "deleted" records and select yourself what will be send to limbo :)

Saboi

1:01 pm on Mar 16, 2007 (gmt 0)

10+ Year Member



Hey guys,

Thanks a lot.Let me try your suggestions taking into consideration all comments made and i will get back to you.

Thanks again.

Saboi

Saboi

5:12 pm on Mar 19, 2007 (gmt 0)

10+ Year Member



Hi,

I have included onClick="javascript:return confirm('do you really want to delete this item?')" and it worked well.In an attempt to have the name to be deleted iw wrote this:

onClick="javascript:return confirm('do you really want to delete <?php echo"$name";?>?')"

However this did not work.Please advice, where did i go wrong?And oh, i have defined the variable $name already.

Please advice and thanks.

Scally_Ally

9:51 am on Mar 20, 2007 (gmt 0)

10+ Year Member



you dont have to put it inside comments
<?php echo"$name";?>
should be
<?php echo $name;?>

but that shouldnt make any difference really.
It deffinately sounds like the variable is not being set. Try just echoing it out at the top of the page.

[edited by: Scally_Ally at 9:53 am (utc) on Mar. 20, 2007]