visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Languages :: PHP :: Asking confirmation before DELETE


By: xedstr U.S.A.  Date: 08/06/2003 00:00:00  English  Points: 500 Status: Answered
Quality : Excellent
Hi,

I use fllowing parts in my code :

CODE =>
...
if($_GET['action']=="delete")
{ $result2 = mysql_query("DELETE FROM link WHERE QuestionNr=$id",$con);
....//and other delete actions
}

<form>
<input type=hidden name="id" value="<?php echo $id ?>">
<input type='submit' value='Delete question' name='delete' o onclick='checkBeforeDeleteQuestion()'>

<input type="button" Name= "delete" value="Delete" onClick="
if (confirm('Do you wish to delete?'))
{this.form.action='<? $_SERVER['PHP_SELF']."?action=delete" ?>';this.form.submit();}">
</form>

___________________________
This code is not doing what I intended to do...
If I press OK in the confirm-screen => I get only redirected to the same screen without any delete.

Can anyone help me out of here? Is there a better solution (using only PHP for example)?

Thanks in advance,
EDS


By: bljak Date: 08/06/2003 20:16:00 English  Type : Comment
this line
{this.form.action='<? $_SERVER['PHP_SELF']."?action=delete" ?>
should be rather
{this.form.action='<? echo $_SERVER['PHP_SELF']."?action=delete"; ?>

and i am not sure about JavaScript syntax this.form.action

//bljak
By: VGR Date: 08/06/2003 20:20:00 English  Type : Comment
CODE =>
...
if($_GET['action']=="delete")
{ $result2 = mysql_query("DELETE FROM link WHERE QuestionNr=$id",$con);
....//and other delete actions
}

<form name=toto method=post action="">
<input type=hidden name="id" value="<?php echo $id ?>">
<input type="button" Name= "delete" value="Delete" onClick="
if (confirm('Do you wish to delete?'))
{document.toto.action='<? $_SERVER['PHP_SELF']."?action=delete" ?>';document.toto.submit();}">
</form>


I don't think this is necessary :
<input type='submit' value='Delete question' name='delete' onclick='return checkBeforeDeleteQuestion(),'>


By: bljak Date: 08/06/2003 20:23:00 English  Type : Comment
However tested your code how it is and it redirects me to same page with ?id=xxx
meaning it submits name and value from hidden
i am not great JavaScript expert but it's JavaScript error however

//bljak
By: VGR Date: 08/06/2003 20:31:00 English  Type : Comment
in my proposal, and althought it's considered bad practice :D, I left the $action being in $_GET and the $id in $_POST

for security and such
By: xedstr Date: 08/06/2003 20:57:00 English  Type : Comment
I used before the following javascript but it was not correct because, even if the user presses CANCEL, the delete is performed...

<script language="javascript" type="text/javascript">
function checkBeforeDeleteQuestion()
{ var answer;
answer=confirm("Are you sure this question must be deleted?");
if(answer!=true)
{ return answer;
}
else
{
return false;
}
}
</script>

-----------------
So, I prefer another way to solve this problem... using php.
The first time the users enters the page : only the id-number is mentioned.
On the page, the visitor can view the information and eventualy delete the item in the database.
When he wants to delete the information, the user must receive a page that asks his confirmation. Only if confirmed, the cancel-proces may take place.

I think this must be possible to code in PHP, from 1 page. Can anyone help me to get me on track?

EDS


By: VGR Date: 08/06/2003 21:27:00 English  Type : Answer
this should work :
<script language="javascript" type="text/javascript">
function checkBeforeDeleteQuestion()
{ var answer;
return confirm("Are you sure this question must be deleted?");
}
</script>


<input type='submit' value='Delete question' name='delete' onclick='return checkBeforeDeleteQuestion();'>


you had forgotten the "return ..."
By: xedstr Date: 08/06/2003 22:07:00 English  Type : Comment
I have in fact reformed completely my page and used PDP this way :

Below you will find the structure .
In the delete I ask the user for confirmation and after that he has choosen YES he gets the confirmation for the delete with possibility to go to another page.

<?php

if(isset($_GET['action']))

$action = $_GET['action'];

else

$action = '0';



switch ($action) {

case 'add':

echo "Add.";

break;

case 'edit':

echo "Edit.";

break;

case 'deleteConfirmed':

echo "DeleteConfirmed.";

break;

case 'delete':

echo "Delete.";

break;

default:

?>



<html>
<title></title>
<body>
<a href="/checkbook/index.php?action=add">Add</a>

<a href="/checkbook/index.php?action=edit">Edit</a>

<a href="/checkbook/index.php?action=delete">Delete</a>

</body>
</html>

<?php

break;

}

Do register to be able to answer

EContact
browser fav
page generated in 1513.103010 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page